php 忽略ajax请求的粘贴帖子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 忽略ajax请求的粘贴帖子相关的知识,希望对你有一定的参考价值。


http://bitsandbabble.com/2013/10/ignoring-sticky-posts-in-a-wordpress-query/

https://codex.wordpress.org/Class_Reference/WP_Query

<?php

// FOR REGULAR POSTS
function more_posts_ajax(){
    $offset = $_POST["offset"];
    $post_per_page = $_POST["post_per_page"];
    header("Content-Type: text/html");

    $args = array(
        'post_type' => 'post',
        'posts_per_page' => $post_per_page,
        'ignore_sticky_posts' => true,
        'post__not_in' => get_option( 'sticky_posts' ) ,
        'offset' => $offset,
    );

    $posts = new WP_Query( $args );

    if( $posts->have_posts() ) :

        while( $posts->have_posts() ) :
            $posts->the_post();
            $terms = get_the_terms( $post->ID, 'category' ) ;

            foreach ( $terms as $term ) : ?>

                <div class="mix <?php foreach ( $terms as $term ) echo $term->slug . ' ' ;  ?>">
                    <div class="blurb box-highlight blurb__margin">
                        <div class="post_date"><?php echo date("M d, Y", strtotime( get_the_date() )  ); ?></div>

                        <h3 class="blurb-title mb-3"><?php echo $posts->post->post_title ;  ?></h3>

                        <p class="blurb-textarea">
                            <?php the_excerpt() ;  ?>
                        </p>

                        <div class="blurb-categories">
                            <?php // get the categories for this post
                            $cats = get_the_terms( $post->ID, 'category'  ) ;
                            foreach ( $terms as $term ) echo  '<span class="post_cats">'. $term->name .'</span>'; ?>
                        </div>

                        <p>
                            <a href="<?php the_permalink() ; ?>" class="btn btn-secondary" target="">Read more</a>
                            <a title="Book online" target="_blank" class="btn btn-primary" href="https://www.zocdoc.com/practice/south-florida-sinus-and-allergy-center-14172?referrerType=widget" data-ps2id-api="true">Book online</a>
                        </p>
                    </div>
                </div>  <!-- END mix container -->

            <?php
            endforeach;
            wp_reset_postdata();

        endwhile ;

    endif;


    exit;
} // END more_posts_ajax
add_action('wp_ajax_nopriv_more_posts_ajax', 'more_posts_ajax');
add_action('wp_ajax_more_posts_ajax', 'more_posts_ajax');

以上是关于php 忽略ajax请求的粘贴帖子的主要内容,如果未能解决你的问题,请参考以下文章

用php获取ajax帖子

php 显示最近的帖子,没有粘贴帖子

ajax的$.get()方法和tomcat服务器的交互

php 帖子em destaque - 粘贴帖子

php脚本得到两个ajax请求,只返回一个?

php 排除粘贴帖子