2016-01-23 61 views
0

我一直在努力表明用戶已經不使用這個WordPress插件青睞的職位名單:https://en-gb.wordpress.org/plugins/favorites/需要顯示從搜索結果negitive(WordPress的插件)

我重新創建一個搜索,我可以製作成自定義短代碼,但我無法弄清楚如何將其反轉爲顯示不受歡迎的列表。

此外,我想顯示標題,並有頁面的標題鏈接 - 任何人都可以幫忙嗎?這是我有:

$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; 

回答

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(陣列) - 使用後的ID。指定後不要檢索。如果 在與post__in相同的查詢中使用,它將被忽略。

但請注意,返回的帖子數量可能很大,posts_per_page爲-1。

+0

非常感謝,我花了9個小時試圖解決這個問題。 –

+0

不客氣,很高興聽到你正在尋找的東西。 @JoeMarshall – birgire