Ignore and posts per page cancel each other out in get_posts
-
I have a simple get_posts query (in author.php) which has an include for an array/string of IDs and a posts per page parameter. These 2 don’t seem to work well together here.
When posts per page and include are set, posts per page is ignored.
If I remove the included array/string, posts per page ‘starts working’.Tested on a vanilla wordpress with twentyfifteen theme.
This is my entire query:
$rows = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_key LIKE %s AND meta_value = %s ", 'idf_tagged_riders_%_member', // meta_name: $ParentName_$RowNumber_$ChildName $user_id ) ); if ( $rows ) { $post_ids = array(); $id_string = ''; // loop through rows and build array of posts to sort them by post_date foreach ( $rows as $row ) { $post_ids[] = $row->post_id; } $id_string = implode( ',', $post_ids ); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $mentioned_args = array( 'posts_per_page' => '2', 'include' => $id_string, 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC', ); $context[ 'mentioned' ] = get_posts( $mentioned_args ); }
When I dump $rows, all expected rows are there.
Dito for $post_ids and $id_string.I built quite a few sites but I’ve never seen this happen before.
There’s no pre_get_posts action which is active (I checked). The entire file which contains them is commented out.
- The topic ‘Ignore and posts per page cancel each other out in get_posts’ is closed to new replies.