Support

Account

Home Forums General Issues Query for posts with the same day and month in the past

Helping

Query for posts with the same day and month in the past

  • Hi,

    I have a Custom Post Type about events in the past width a date Custom Field. I would like to query the events that occurred the same day in the past. It´s easy to do that with the publication date using monthnum and day parameter but I not guess the way to do with custom fields.
    Any ideas?

    Thanks in advance.

  • Hi Rafaromo,

    You could use this

    $args = array (
        'post_type' => 'YourPostType',
        'meta_query' => array(
    		array(
    	        'key'		=> 'start_date',
    	        'compare'	=> '=',
    	        'value'		=> $TheDateYouAreLookingFor,
    	    )
        ),
    );
    
    // get posts
    $posts = get_posts($args);

    I got this from the ACF guide: https://www.advancedcustomfields.com/resources/date-picker/

    The can also be used with the regular WP Query. The date you are looking for needs to be in the same format as the custom field date that is saved to the database.

    Hope this helps,
    Neasa

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.