[英]Wordpress Query for custom post type new addition
如果要在wordpress admin中添加新的帖子类型,我想在php变量中获取布尔值(真/假)。
现在我有这段代码
<?php
$popularpost = new WP_Query( array('post_type' => 'product','date_query' => array( array( 'after' => '-3days' ) ) ) );
$v=1; while ( $popularpost->have_posts() ) : $popularpost->the_post();
if($v >=1){
$_SESSION["newproduct"] = "newproduct";
?>
<script>
$( ".shop > a" ).after( "<span>New</span>" );
</script>
<?php } ?>
<?php $v++; endwhile; wp_reset_query(); ?>
在下面的示例中,首先显示所有产品的列表。 如果三天前发布,则会在它们旁边创建一个新标签
<?php
$popularpost = new WP_Query( array('post_type' => 'product') );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
$post_data = strtotime( get_post( get_the_ID() )->post_date );
$before_3_days = time() - (3 * 24 * 60 * 60);
if($post_data >$before_3_days) {
?>
<script>
$( ".shop > a" ).after( "<span>New</span>" );
</script>
<?php } ?>
<?php endwhile; wp_reset_query(); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.