This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Search insists on showing 9 posts_per_page

Viewing 13 replies - 1 through 13 (of 13 total)
  • Author
    Replies
  • #20646
    John
    Participant

    Even if I set $wp_query->set( ‘posts_per_page’, ’16’ );themeblvd_the_loop();

    in content-page-search.php and dump the query to verify.

    if I take search display out of grid mode, it then inherits the posts_per_page form wordpress settings (i.e. default 10).

    #20653
    Jason Bobich
    Keymaster

    if I take search display out of grid mode …

    What does this mean? How are you putting search results in grid mode? Programmatically, you mean? And yes, if you’re using grid mode, then the posts page page is taken over.

    Note that all these query params &post_type=practitioner&posts_per_page=16&orderby=name&order=ASC you’re adding to the end of the search results URL is never going to do anything, unless you’re programmatically doing something with them. WordPress doesn’t work like this. You have to do all this through pre_get_posts action.

    #20660
    John
    Participant

    Ok, got it by using this and not setting to ‘grid’ (yes I was doing that programmatically):

    function jma_pract_search( $query ) {
        if( $query->is_admin || !$query->is_main_query() || true == $query->query_vars['suppress_filters'] ) 
            return;
    
        if ( is_post_type_archive( 'practitioner' ) ) {
            
            $query->set( 'posts_per_page', 2 );
            $query->set( 'meta_key', 'last_name' );
            $query->set( 'orderby', 'meta_value' );
            $query->set( 'order', 'ASC' );
            return;
        }
    }
    add_action( 'pre_get_posts', 'jma_pract_search', 1 );

    On a related point.
    refering to this tutorial:
    http://dev.themeblvd.com/tutorial/extending-the-custom-query/

    Keeping in mind I’m using beta-2 tried this trick, noticed that the filter seems to need an extra parameter (this time just working in a ‘builder grid exactly as in tutorial)’:

    function my_custom_posts_query( $query, $args, $context ){
    	if( $args['query'] == 'my_unique_key' ){
    		$query = array( 
    			'posts_per_page' => 2,
    		);
    	}
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 3 );

    and on the page see:
    Warning: Illegal string offset ‘paged’ in /home2/candygal/public_html/crossinology/wp-content/themes/jumpstart/framework/includes/class-tb-query.php on line 228
    what am I doing wrong?
    thanks as always,
    John

    #20664
    Jason Bobich
    Keymaster

    noticed that the filter seems to need an extra parameter (this time just working in a ‘builder grid exactly as in tutorial)’:

    When you’re working with a filter in WordPress, you can pass in as many available parameters you want; you don’t have to pass in all that are there. If you’re not using the $context parameter, you don’t need to pass it in:

    function my_custom_posts_query( $query, $args ){
    	// ...
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 2 );

    This posts_per_page isn’t meant to me messed with when you’re using a grid. It will be the number of rows times the number of columns you’ve selected in the element.

    #20674
    John
    Participant

    this produces the same result:

    function my_custom_posts_query( $query, $args ){
    	if( $args['query'] == 'my_unique_key' ){
    		$query = array( 
    		'post_type'=> 'practitioner',
    		'orderby' => 'meta_value',
    		'meta_key' => 'last_name',
    		'order' => 'ASC'
    		);
    	}
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 2 );

    results this warning:

    Warning: Illegal string offset 'posts_per_page' in /home2/candygal/public_html/crossinology/wp-content/themes/jumpstart/framework/includes/helpers.php on line 290
    
    Warning: Illegal string offset 'posts_per_page' in /home2/candygal/public_html/crossinology/wp-content/themes/jumpstart/framework/includes/helpers.php on line 304

    followed by the grid.
    It occurs to me that I can achieve my result by using:
    post_type=practitioner&orderby=meta_value&meta_key=last_name&order=ASC

    In the query line, so just thought I would point that out for future reference. Hoping I’m being helpful, not a pain in the …
    Thanks for your help.
    John

    #20677
    Jason Bobich
    Keymaster

    Try adding this to your functions file:

    add_filter('themeblvd_force_grid_posts_per_page', '__return_false');
    #20678
    John
    Participant

    with this as the code:

    function my_custom_posts_query( $query, $args ){
    	if( $args['query'] == 'my_unique_key' ){
    		$query = array( 
    		'post_type'=> 'practitioner',
    		'orderby' => 'meta_value',
    		'meta_key' => 'last_name',
    		'order' => 'ASC'
    		);
    	}
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 2 );
    add_filter('themeblvd_force_grid_posts_per_page', '__return_false');

    i get:
    Warning: Illegal string offset ‘paged’ in /home2/candygal/public_html/crossinology/wp-content/themes/jumpstart/framework/includes/class-tb-query.php on line 228

    #20679
    Jason Bobich
    Keymaster

    Is this a post grid element in the Layout Builder?

    #20680
    John
    Participant

    Yes, grid, with pagination.

    #20688
    Jason Bobich
    Keymaster

    Ok, so I was able to reproduce on my end. It looks like the issue simply happens any time you put in some key you’re going to use for your custom query trigger (without any code or filtering from functions.php). Thanks, I’ll dig into that, and hopefully get it fixed!

    #20689
    Jason Bobich
    Keymaster

    But for future reference, you’re trying to mess with the posts_per_page in a custom query within a grid, and you can’t get your’s to take, throw this in your functions.php:

    add_filter('themeblvd_force_grid_posts_per_page', '__return_false');

    If you’re curious why, see /framework/includes/helpers.php, around line 170 (and /framework/includes/class-tb-query.php around line 140 — same basic thing)

    #20692
    John
    Participant

    THANKS JASON

    #20792
    John
    Participant

    Just a note here. This relates to this thread:
    http://support.themeblvd.com/forums/topic/add-themeblvd-pagination/

    If I use a “legal” query as a “flag” I can then over-write it. I also need to add the ‘paged’ value to the query to get that portion to work. Once again this is using post grid with pagination in the beta-2 builder.
    So this gives the desired result:

    function my_custom_posts_query( $query, $args ){
    	if( $args['query'] == 's=my_unique_query' ){//NOTICE THIS IS A LEGAL QUERY (which I match exactly in the builder)
    		$query = array( 
    		'post_type'=> 'practitioner',
    		'meta_key' => 'last_name',
    		'orderby' => array( 'menu_order' => 'DESC', 'meta_value' => 'ASC' ),
    		'posts_per_page' => 21//IF NOT INCLUDED I GET THE VALUE FROM WORDPRESS SETTINGS (ie 10 by default)
    		);
    	if ( get_query_var('paged') ) {
    		$query['paged'] = get_query_var('paged');
    	} else if ( get_query_var('page') ) {
    		$query['paged'] = get_query_var('page');
    	} else {
    		$query['paged'] = 1;
    	}
    	}
    	return $query;
    }
    add_filter( 'themeblvd_posts_args', 'my_custom_posts_query', 10, 2 );
    //add_filter('themeblvd_force_grid_posts_per_page', '__return_false');//THIS SEEMS TO HAVE NO EFFECT IN THIS CONTEXT

    Just sharing what I have discovered on this. thx

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.