Retrieving list of a custom post type in a widget without using WP_Query?

Use wp_reset_postdata() function after while loop to reset custom wp_query as shown in following code so that it will not break other wordpress loop. <?php // Create and run custom loop $custom_posts = new WP_Query(); $custom_posts->query(‘post_type=jobs&posts_per_page=8’); while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/98851/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endwhile; ?> <?php wp_reset_postdata(); ?> For more … Read more

Programmatically set ‘meta_query’ for filter

A meta_query has to be an array of arrays. You only have an array. A filter needs to return information. Yours doesn’t. Of course, parse_query is an action not a filter, despite your use of add_filter. Use add_action instead. I would use pre_get_posts instead of parse_query. It is the next hook that fires after parse_query … Read more

How can I retrieve comments from last 5 minutes for a post?

Note that the function wp_list_comments() doesn’t fetch the comments, only displays them in various ways depending on the input arguments. You’re actually using the WP_Comment_Query/get_comments input arguments into wp_list_comments(). You could try this instead: $postID = 12345; // Adjust this! $comments = get_comments( [ ‘date_query’ => [ ‘after’ => ‘5 minutes ago’, ‘inclusive’ => true, … Read more

Wp query orderby ‘title’ doesn’t work

Try adding ‘suppress_filters’ => true to your query args. Maybe you have a plugin that modifies the queries. You could also check if the posts out of order (the first one) is a sticky post. Sticky posts by default skip the order queue. You can disable this by adding ‘ignore_sticky_posts’ => true to your query … Read more

Exclude old events from WP_Query with date saved in a `meta_key`

You need something like the following: $args = array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 1, ‘meta_query’ => array( ‘meta_key’ => ‘event_start_date’, ‘type’ => ‘DATETIME’, // You can also try changing it to TIME or DATE if it doesn’t work ‘meta_value’ => date( “Y-m-d” ), ‘meta_compare’ => ‘>’, ), ‘order’ => ‘ASC’ );