Search insists on showing 9 posts_per_page
-
CreatorTopic
-
February 24, 2015 at 5:08 am #20641
John
Participantthis query (or pretty much any search query) shows 9 posts_per_page. The site is set for ten. The searchis comming from the practitioen search form. I’ve tried deactivating plugins. This is the beta-2 ver.
http://crossinology.broomfieldwebette.com/?s=e&post_type=practitioner&posts_per_page=16&orderby=name&order=ASCtried this solution also:
function my_pre_get_posts( $q ) { if( $q->is_search ) $q->set( 'posts_per_page', 12 ); } add_action( 'pre_get_posts', 'my_pre_get_posts' );
-
CreatorTopic
-
AuthorReplies
-
February 24, 2015 at 1:48 pm #20646
John
ParticipantEven 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).
February 24, 2015 at 10:44 pm #20653Jason Bobich
Keymasterif 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.February 25, 2015 at 5:56 pm #20660John
ParticipantOk, 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,
JohnFebruary 25, 2015 at 7:43 pm #20664Jason Bobich
Keymasternoticed 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.
February 26, 2015 at 11:16 am #20674John
Participantthis 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=ASCIn 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.
JohnFebruary 26, 2015 at 6:43 pm #20677Jason Bobich
KeymasterTry adding this to your functions file:
add_filter('themeblvd_force_grid_posts_per_page', '__return_false');
February 26, 2015 at 7:30 pm #20678John
Participantwith 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 228February 26, 2015 at 7:55 pm #20679Jason Bobich
KeymasterIs this a post grid element in the Layout Builder?
February 27, 2015 at 2:05 am #20680John
ParticipantYes, grid, with pagination.
February 27, 2015 at 9:52 pm #20688Jason Bobich
KeymasterOk, 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!
February 27, 2015 at 9:55 pm #20689Jason Bobich
KeymasterBut 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)
February 27, 2015 at 10:29 pm #20692John
ParticipantTHANKS JASON
March 6, 2015 at 2:22 pm #20792John
ParticipantJust 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
-
AuthorReplies
- You must be logged in to reply to this topic.