需要显示搜索的负面结果(Wordpress插件)

时间:2016-01-23 20:43:42

标签: php wordpress

我一直在努力展示用户不喜欢使用此wordpress插件的帖子列表:https://en-gb.wordpress.org/plugins/favorites/

我已经重新创建了一个我可以制作自定义短代码的搜索,但我无法解决如何将其反转以显示不受欢迎的代码。

此外,我想显示标题并将标题链接到页面 - 任何人都可以帮忙吗?这就是我所拥有的:

$favorites = get_user_favorites();

    if ( $favorites ) :

    $favorites_query = new WP_Query( array(
        'post_type' => 'product',
        'posts_per_page' => -1,
        'post__in' => $favorites
    ));

    if ( $favorites_query->have_posts() ) :

        while ( $favorites_query->have_posts() ) : $favorites_query->the_post();

            echo '<p>' . get_the_title( $favorite ) . '</p>';

        endwhile;

    endif;

    wp_reset_postdata();

endif;

1 个答案:

答案 0 :(得分:0)

我想知道你的意思是:

 $favorites_query = new WP_Query( array(
        'post_type' => 'product',
        'posts_per_page' => -1,
        'post__not_in' => $favorites
    ));

我们使用post__not_in代替post__in

来自Codex

  

post__not_in(数组) - 使用post id。指定要检索的帖子NOT。如果   这与post__in在同一查询中使用,将被忽略。

但请注意,返回的帖子数量可能很大,posts_per_page为-1。