I am attempting to extract all "Activity" Post Type entries created on the <strong>current day</strong> with a slug <strong>similar</strong> to "yoga-km5t112-registration".
My query looks like this ...
<?php
$day == date('d'); // Currently using Server day value, but want to use WordPress day created value
$args = array( 'post_type'=>'activities', 'name'=>'yoga-km5t112-registration', 'day'=>$day, 'posts_per_page' => 50 );
$loop = new WP_Query( $args ); ?>
<?php if ( $loop->have_posts() ) : ?>
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $participant_name = get_post_meta($post->ID, 'activity_participant_name', true); ?>
<li><?php echo get_the_date(); ?> - <?php echo $participant_name; ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
1) Currently, my query is doing an <strong>exact</strong> match on the slug. How do I perform a <strong>like</strong> operation with the <strong>name</strong> parameter so all similar slug variations are captured? i.e. "yoga-km5t112-registration", "yoga-km5t112-registration-2", "yoga-km5t112-registration-3" etc
2) I am currently using the Server date('d') function for my day condition. Instead, I would like to use the date WordPress assigns to my posts (as set in Settings > General > Date Format) to extract the correct day information. My server is in the USA, but I am in New Zealand. My WordPress Timezone is thus set to "Auckland".
Thank you
Arnav Joy answers:
modify your query like
<?php
$day == date('d'); // Currently using Server day value, but want to use WordPress day created value
$str= 'yoga-km5t112-registration';
$mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_name LIKE '".$str."%' ");
$args = array(
'post__in'=> $mypostids,
'post_type'=>'activities',
'day'=>$day,
'posts_per_page' => 50
);
$loop = new WP_Query( $args ); ?>
<?php if ( $loop->have_posts() ) : ?>
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $participant_name = get_post_meta($post->ID, 'activity_participant_name', true); ?>
<li><?php echo get_the_date(); ?> - <?php echo $participant_name; ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
for date of wordpress you can use following
$date_format = get_option('date_format');
designbuildtest comments:
Hi Arnav, this doesn't work sorry. I think I saw a derivitive of your suggestion on StackExchange - [[LINK href="http://wordpress.stackexchange.com/questions/22949/query-post-by-title"]][[/LINK]]
The above code is attempting to match/filter by Post Title, rather than Slug???
Arnav Joy comments:
designbuildtest comments:
Thanks Arnav. Your revised solution got me 80% there. I had to do a wee bit of searching to get the time parameters to work properly, but eventually I managed to piece everything together. Cheers.