Get posts with condition on comment meta value

You can first try the following comment query: $comments = get_comments( [ ‘post_type’ => ‘projects’, ‘post_status’ => ‘publish’, ‘type’ => ‘message’, ‘date_query’ => [ [ ‘before’ => ‘5 days ago midnight’, ‘inclusive’ => true, ] ], ‘meta_query’ => [ [ ‘key’ => ‘foo’, // <– Adjust to your needs! ‘value’ => ‘bar’ // <– Adjust … Read more

latest 5 posts using switch_to_blog loop

No, it’s retrieving the posts just fine, but you’re not storing them anywhere. Here’s your code again, with line-by-line documentation: // Set up global variables. Great global $wpdb, $blog_id, $post; // Get a list of blogs in your multisite network $blog_ids = $wpdb->get_col( “SELECT blog_id FROM $wpdb->blogs” ); // Iterate through your list of blogs … Read more

Meta Query with date and time on the same Day before given time

Found the error: $args = array( “posts_per_page” => 12, “paged” => $paged, “post_type” => array( “event”, “post” ) , “post_status” => “publish”, “meta_key” => “_thumbnail_id”, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘event_start’, ‘value’ => date(“Y-m-d H:i:s”) , ‘compare’ => ‘>=’, ‘type’ => ‘DATETIME’ ) , array( ‘key’ => ‘event_start’, ‘compare’ => ‘NOT … Read more

How to get previous 10 days post from a specific date – WP Query

Yes, it is possible. You can pass full date as before and after params, so: $given_date_as_time = strtotime(‘2017-11-22 00:00:00’); $args = array( ‘post_type’ => ‘post’, ‘date_query’ => array( ‘before’ => date( ‘c’, $given_date_as_time ), ‘after’ => date(‘c’, strtotime( ‘- 10 days’, $given_date_as_time ) ), ), ); $query = new WP_Query( $args ); above query is … Read more

get_posts not finding argument: post_name

Aha, despite there being a postmeta field of post_name->’slug’, the correct syntax (which mirrors that of WP_Query, is $args = array( ‘name’ => $postSlug, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $slugPosts = get_posts($args); Where ‘name’ is the key in the query (for posts, ‘postname’ for page). Doesn’t make much sense but might as well … Read more

Get_post() with meta_key when compare is a date

I think you have error in your query. Please try this: $posts = get_posts(array( ‘post_type’ => ‘events’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘meta_key’ => ‘from_datetime’, ‘type’ => ‘DATETIME’, // You can also try changing it to TIME or DATE if it doesn’t work ‘meta_value’ => date( “F d, Y g:i a” ), ‘meta_compare’ => … Read more

Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?

Hi @janoChen: If you have a choice, go with WP_Query. Both of the other functions (query_posts() and get_posts()) call WP_Query indirectly. The former is designed to allow you to modify the main query after the standard query has already been run, for example when you want a second loop. But query_posts() affects global variables and … Read more