Forums Forums Search & Filter Pro Custom Post Types – Adding S&F Arg Breaks Args in WP_Query

Viewing 7 posts - 1 through 7 (of 7 total)
  • Anonymous
    #185615

    I’m using custom post type, a custom query, and a custom template. When I do this, it displays the post where type = authors:

    $args = array('post_type' => 'authors', 'cat' => $cat_id, 'meta_key' => 'author_last_name', 'orderby' => 'meta_value', 'order' => 'asc');
    //$args['search_filter_id'] = 154;
    $query = new WP_Query($args);

    Note that the line with seach_filter_id is commented out.

    When I uncomment that line, I just get all posts (as if there were no args passed to WP_Query).

    Any idea what I might be doing wrong? Thanks.

    P.s. This works:

    $thePosts = query_posts("cat=$cat_id&posts_per_page=100&search_filter_id=154&meta_key=author_last_name&orderby=meta_value&order=asc");

    But when I add the arg for my custom post type, it doesn’t work:

    $thePosts = query_posts("cat=$cat_id&posts_per_page=100&search_filter_id=154&meta_key=author_last_name&orderby=meta_value&order=asc&post_type=authors");

    It just returns posts as if there were no args passed to query_posts. That’s why I switched to usign WP_Query, because the post_type filtering works. But the S&F doesn’t 🙁

    Thanks.

    Trevor
    #185632
    This reply has been marked as private.
    Anonymous
    #185690
    This reply has been marked as private.
    Trevor
    #185692

    Ah, I can see, you need to select the Post Types in the search form. You have it set to Posts right now.

    Any other conditions need to be set in the Tags, Categories and Taxonomies settings tab and the Post Meta settings tab.

    Any filters you set as arguments are overwritten by our query.

    Anonymous
    #185712

    Yep, that did the job. Thanks.

    Anonymous
    #185714

    That’s all working. Great. Thanks!

    Now I’d like to try to make it work with Ajax. All my settings are the same as above except I’ve selected the Authors post type and unselected Posts.

    When I select Load results using Ajax, then the filter doesn’t work.

    I’m doing all this on a page with the following content:

    [searchandfilter id="154"]
    
    [searchandfilter id="154" show="results"]

    And this page uses this custom template, which queries the db to get category names, then within each category queries to get posts. FYI each post can only have one category. Otherwise I’m aware that a given post could show up more than once on the page.:

    <?php
    /* template name: Authors Page */
     ?>
    <?php get_header(); ?>
     <div id="layout" class="pagewidth clearfix">
         <div id="content" class="authors-page clearfix">
        <?php
        //echo do_shortcode('[searchandfilter id="154"]');
        // get all the categories from the database
        $cats = get_categories(); 
    	// loop through the categries
    	foreach ($cats as $cat) 
    		{
    		// setup the cateogory ID
    		$cat_id= $cat->term_id;            // create a custom wordpress query
    		$args = array('post_type' => 'authors', 'cat' => $cat_id, 'meta_key' => 'author_last_name', 'orderby' => 'meta_value', 'order' => 'asc');
    		$args['search_filter_id'] = 154;
    		$query = new WP_Query($args);
    		$count = $query->found_posts;
    		if($count > 0) //fix this to test if there are any results (numrows > 0)
    			{
    			// Make a header for the cateogry
    			echo "<h2 class=\"category-name background\" style=\"clear:both\"><span>".$cat->name."</span></h2>";
    			}
    ?>
                        
         <div id="loops-wrapper" class="loops-wrapper sidebar1 grid3  boxed masonry infinite masonry-done blog" style="position: relative; height: 640.234px;">
         <div class="grid-sizer"></div>
         <div class="gutter-sizer"></div>
        <?php
        // start the wordpress loop!
     	if ( $query->have_posts() ) : ?>
    		<?php while ( $query->have_posts() ) : $query->the_post(); ?>	
    			<article id="post-<?php echo get_the_ID();?>" class="post clearfix post-<?php echo get_the_ID();?> type-post status-publish format-standard has-post-thumbnail hentry category-featured-authors has-post-title no-post-date " style="position: absolute; left: 0px; top: 500px;">
    			 <figure class="post-image  clearfix">
    				<a href="<?php the_permalink();?>"><img src="<?php echo get_the_post_thumbnail_url(); ?>" class=" wp-post-image wp-image-84" alt="<?php the_title(); ?>" srcset="" sizes="(max-width: 200px) 100vw, 200px" width="200" height="150"><img src="<?php the_field('featured_book_cover_image'); ?>" class="featured_title_cover_image" width="100" height="150"></a>
    				<a href="<?php echo esc_url( get_permalink() ); ?>" class="overlay">
    				<div class="excerpt-text"><?php the_field('mini_blurb'); ?></div>
    				</a>
    			  </figure>
    			  <div class="post-content">
    				<div class="post-content-inner">
    				<!-----------------ICON----------------->
    					<!--<span class="<?php if($on_list) { echo $icon_class; } ?> tooltips author-tooltips add_<?php echo get_the_ID();?> list-icon"  title="<?php echo $element_title; ?>">
    						<?php if(!$on_list) { ?><a href="#" class="<?php echo $icon_class; ?> btnAddAction" onclick = "cartAction('<?php echo $action; ?>','<?php echo get_the_ID();?>')"></a> <?php } ?>
    					</span>	-->
    				   <!-----------------/.ICON------------------>
    					<h2 class="post-title entry-title"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
    					<div class="entry-content">
    					   <?php the_field('featured_book_title'); ?>
    					</div><!-- /.entry-content -->
    				</div><!-- /.post-content-inner -->
    			  </div><!-- /.post-content -->
    		 </article>
    		<?php endwhile; wp_reset_postdata(); ?>
    		<!-- show pagination here -->
    	<?php else : ?>
    		<!-- show 404 error here -->
    	<?php endif; ?>
        </div><!-- #loops-wrapper -->
    <?php } // done the foreach statement ?>
    
    	</div><!-- #content -->
    </div><!-- #layout -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    This all works fine, except when I set it to use Ajax.

    Thanks.

    Trevor
    #185743

    You are using our shortcode display results method? That uses a partial template which slots into your page.php template (and that template calls the header, footer etc, so your template, if that is what you are using for the results.php file, has too much in it. Compare it to our standard results.php exemplar (in the templates folder of the plugin).

Viewing 7 posts - 1 through 7 (of 7 total)