wp query for popular post with simple field

The correct query is: $args1 = array( ‘showposts’ => 5, ‘ignore_sticky_posts’ => 1, //ORDER ARGUMENTS ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_key_num’, ‘order’ => ‘DESC’, //META QUERY ‘meta_query’ => array( array( ‘key’ => ‘_simple_fields_fieldGroupID_2_fieldID_1_numInSet_0’, ‘compare’ =>’NOT EXISTS’ ), ), ); $popularposts = new WP_Query($args1); The order aguments are always outside meta_query, see the codex.

Trying to retrieve random post, getting a page

You need to specify the post type to be a post – try this for your $args instead: $args = array( ‘post_type’ => ‘post’, // Specifying you want posts only ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’, ‘post_status’ => ‘publish’, ); And most importantly, you need to apply the $args to your query, so do this … Read more

Using custom taxonomies in a query

I looked at the source code for IssueM. I think the slug you are after is issuem_issue However, there are two more taxonomies it registers: issuem_issue_categories and issuem_issue_tags Edit Try changing your args to: $args = array( ‘post_type’ => ‘article’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘issuem_issue’, ‘field’ => ‘slug’, ‘terms’ => ‘issue-one’ ), ), … Read more

problems with comments_number()

comments_number() echo’s the number of comments, while get_comments_number() returns the number of comments as a string, so what you are likely looking for is get_comments_number instead of comments_number, like echo ‘<ul>’; while ( $query->have_posts() ) { $query->the_post(); $title = get_the_title(); echo ‘<li>’ . $title . get_comments_number() . ‘</li>’; } echo ‘</ul>’; https://codex.wordpress.org/Template_Tags/get_comments_number

Searching for meta_key returns 0 posts

To narrow down the possible causes I’d strongly recommend using a debugging plugin on your development server, like Query Monitor, so you can see the SQL being generated by your query. Alternatively check the request property of your $wp_query object. It’s always possible, if you only recently installed the plugin, that there aren’t any posts … Read more

new WP_Query messes up pagination

If I understand you correctly you just want to display a different amount of posts at archives, for this you don’t need a custom secondary query at all. You can control it via pre_get_posts hook, either making use of posts_per_page or posts_per_archive_page parameter. Example for pre_get_posts function wpse188786_different_number_of_posts_for_archive_ppp( $query ) { if ( !is_admin() && … Read more

Modifing archive query affects show post count function

pre_get_posts does not explicitely changes the value in the db of posts_per_page, this value stays constant to the value set in the back end under the readings settings. pre_get_posts only changes this value before the SQL query is build in WP_Query right before the main query runs. If you need to get the exact ( … Read more