admin管理员组

文章数量:1289868

I turn to you since I tried by my means but I could not achieve it It turns out that I have the need to create an rss file to use it in external applications, I have a type of post (events) which contains a metakey with the date I need or the field I need to filter.

In a few words, what I need is a query that allows me to show the events of the current day, this by consulting the date field that contains the metakey. for now I have done the following:

date_default_timezone_set('America/Tegucigalpa');
     $hoy = date('d');
    require_once( 'wp-load.php' );
   $events = new WP_Query(
    array(
        'post_type'=>'ajde_events',
        'posts_per_page'=>10,
        'post_status'=>'publish',
        $meta_query = array(
            array(
        'key'     => 'meta_key',
        'value'   => 'evcal_srow',
        'compare' => '=',
        'type'    => $hoy,
    )
)
    )
); 

With the above code I can show the last 10 events added, the metakey that saves the date is called evcal_srow

try the following:

   while($events->have_posts()): $events->the_post();
    
                $event_meta = get_post_custom($events->post->ID);
    
                // featured image
                $output= false;
                if(has_post_thumbnail($events->post->ID)){
                    $output = get_the_post_thumbnail( $events->post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
                }
                $image = $output? $output:null;
    
                // event date/times
                $today= date('d', $event_meta['evcal_srow'][0]);


             
    if ($hoy == $today){
                        
                        
                        /// eventos today
                        
                    }
endwhile;
     

With the above it does not show the events, so I did a little research and I think the best way is to assign the metakey the current date

本文标签: Query to show post current day