小编Jon*_*ing的帖子

当有匹配的帖子时,WP_Query有时会返回零结果 - 为什么?

这个让我难过.

我有一个包含此循环的category.php文件:

<?php
if ( have_posts() ) : ?>
    <?php
    while ( have_posts() ) : the_post(); ?>
        <div class="entry-content description clearfix">
            <h2 class="category-subtitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php echo the_content(); ?>
            <?php global $withcomments; $withcomments = 1;
    ?>
        </div><!-- .entry-content -->
    <?php
    endwhile;
else :
    get_template_part( 'content', 'none' );
endif;
?>
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,并始终返回预期的结果.

另外,在循环之外(在它之后,如果重要的话),我有一个列到这一循环的一侧 - 为了清楚起见,我将把它称为新闻源循环:

<h3 class="newsfeed-heading"><a href="/category/news/">Latest News</a></h3>
<?php
    // wp_reset_query(); * Same results with or without wp_reset_query
    $args = array(
    'cat' => 89,
    'order'   => 'ASC'
    ); …
Run Code Online (Sandbox Code Playgroud)

wordpress wp-query

7
推荐指数
2
解决办法
1636
查看次数

ReferenceError:通过Ajax加载Wordpress帖子时未定义ajax_object

我一直在尝试在这个帖子中实现@SagiveSEO的推荐: 通过Ajax加载单个帖子的正确方法?

想法:点击一个按钮并通过AJAX加载帖子.我们的想法是,您将拥有一个按钮树,以便人们快速浏览有用的内容.

不幸的是,它失败了.

在控制台中,我收到消息"ReferenceError:ajax_object is not defined",它引用了行"$ .post(ajax_object.ajaxurl ...")

我究竟做错了什么?

这是我的HTML:

<button class="get_project" data-postid="3300">PROJECT NAME</button>
                <div class="postcontainer"></div>
Run Code Online (Sandbox Code Playgroud)

这是我的Javascript:

    jQuery(function($){
    $('.get_project').click(function() {
        var postid = $(this).data('postid'); // Amended by @dingo_d
        $.post(ajax_object.ajaxurl, {
            action: 'my_load_ajax_content ',
            postid: postid
        }, function(data) {
            var $response   =   $(data);
            var postdata    =   $response.filter('#postdata').html();
            $('.postcontainer').html(postdata);
        });

    })
    //alert( "hello world" );
});
Run Code Online (Sandbox Code Playgroud)

这是我的functions.php文件中的php:

function my_load_ajax_content () {

    $pid        = intval($_POST['post_id']);
    $the_query  = new WP_Query(array('p' => $pid));

    if ($the_query->have_posts()) {
        while ( $the_query->have_posts() ) {
            $the_query->the_post();

            $data …
Run Code Online (Sandbox Code Playgroud)

ajax wordpress

2
推荐指数
1
解决办法
5596
查看次数

标签 统计

wordpress ×2

ajax ×1

wp-query ×1