admin管理员组文章数量:1287273
I want to print posts if Custom Field Value (Expiry) formatted as 31 April 2021 is equal to or greater than today date (19 April 2021). I have tried with the below code but not working.
<table>
<thead>
<tr>
<th>Title</th><th>Click</th>
</tr>
</thead>
<?php
$today = strtotime(date('d F Y'));
$datecf = get_post_meta($post->ID, 'Expiry', true );
$cfdate = (!empty($datecf))? strtotime($datecf) : false;
if($today <= $cfdate){
?>
<tbody>
<tr>
<td><?php the_title(); ?></td>
<td><a href="<?php the_permalink(); ?>">Check Here</a> </span> </td> </tr>
<?php
}
// Posts not found
else {
?>
<tr>
<td><p>There is no Active Posts Now, Check Tommorrow!</p></td>
</tr>
<?php
}
?>
</tbody>
</table>
I want to print posts if Custom Field Value (Expiry) formatted as 31 April 2021 is equal to or greater than today date (19 April 2021). I have tried with the below code but not working.
<table>
<thead>
<tr>
<th>Title</th><th>Click</th>
</tr>
</thead>
<?php
$today = strtotime(date('d F Y'));
$datecf = get_post_meta($post->ID, 'Expiry', true );
$cfdate = (!empty($datecf))? strtotime($datecf) : false;
if($today <= $cfdate){
?>
<tbody>
<tr>
<td><?php the_title(); ?></td>
<td><a href="<?php the_permalink(); ?>">Check Here</a> </span> </td> </tr>
<?php
}
// Posts not found
else {
?>
<tr>
<td><p>There is no Active Posts Now, Check Tommorrow!</p></td>
</tr>
<?php
}
?>
</tbody>
</table>
Share
Improve this question
asked Apr 18, 2021 at 17:51
PuneetPuneet
477 bronze badges
1 Answer
Reset to default 1In this example , suppose expiry date is (19 April 2021) AND also your Today Date is equal like(19 April 2021) or greater then Like Tomorrow date (20 April 2021),So You will get all the posts from today's date, Here, date format is (dd-mm-yyyy) as defualt (19-04-2021). But, as your requirement format ('d F Y') like this (19 April 2021). So, as per my example you can use this format Like $today = strtotime(date('d F Y')); But must remember that, Your posts Custon field return value As per your requirement date format.
<table>
<thead>
<tr>
<th>Title</th>
<th>Click</th>
</tr>
</thead>
<?php
// $today = strtotime(date('d F Y'));
$today = date('Y-m-d');
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'expire_date',
'value' => $today,
'compare' => '<=',
'type' => 'DATE'
)
)
);
$query = new WP_Query($args);
$ex_date = get_post_meta($post->ID, 'expire_date', true);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
?>
<tbody>
<tr>
<td><?php the_title(); ?></td>
<td><a href="<?php the_permalink(); ?>">Check Here</a></td>
</tr>
<?php
}
?>
<?php
} else {
?>
<tr>
<td><p>There is no Active Posts Now, Check Tommorrow!</p></td>
</tr>
<?php
}
?>
</tbody>
</table>
本文标签: Print Posts if Custom Field Value Date equal or greater than Today Date
版权声明:本文标题:Print Posts if Custom Field Value Date equal or greater than Today Date 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741243313a2364403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论