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

Every second post different class in blog view

Give this a try? function oddeven_post_class ( $classes ) { global $current_class; $classes[] = $current_class; $current_class = ($current_class == ‘odd’) ? ‘even’ : ‘odd’; return $classes; } add_filter ( ‘post_class’ , ‘oddeven_post_class’ ); global $current_class; $current_class=”odd”; and be sure you’re using <?php post_class(); ?>

WP_Query() with custom post type and taxonomy — get all terms?

I would rather use a full proper tax_query here. The {tax} syntax is depreciated according to the docs A tax_query is also better here as you will be dealing with an array of terms. When your URL is http://www.myWebsiteURL.com/lessons this means that all terms should be displayed. So this means that you need to use … 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