代码之家  ›  专栏  ›  技术社区  ›  Sonia

自定义文章类型新添加的Wordpress查询

  •  0
  • Sonia  · 技术社区  · 6 年前

    如果在wordpress admin中添加了新的post类型,我想在php变量中获得一个布尔值(true/false)。

    现在我有了这个密码

    <?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(); ?>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Mehrshad Darzi    6 年前

    在下面的示例中,首先显示所有产品的列表。 如果三天前发布,将在它们旁边创建一个新标记

     <?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(); ?>