You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WordPress的WP_Query查询中排除指定的3个Agent类型文章ID

How to Exclude Specific Agent Posts from Your WP_Query

Hey Claudio, glad to help you tweak that WP_Query! Excluding those three agent posts by ID is super straightforward with WordPress's built-in post__not_in parameter. Here's exactly how to update your code:

Modified Code Snippet

// Initialize the query args with the exclusion parameter
$agents_query = array(
    'post_type'      => 'agent',
    'posts_per_page' => $number_of_posts,
    'paged'          => $paged,
    'orderby'        => 'rand',
    'post__not_in'   => array(5707, 5782, 5755) // This line excludes your target agent posts
);

// Apply your existing sorting function
$agents_query = inspiry_agents_sort_args( $agents_query );

// Initialize the query
$agent_listing_query = new WP_Query( $agents_query );

Key Details:

  • The post__not_in parameter accepts an array of post IDs you want to exclude from the query results.
  • Since your inspiry_agents_sort_args() function likely only adjusts sorting-related parameters (like orderby or order), it won't interfere with the post__not_in filter—your excluded posts will stay excluded after sorting is applied.
  • Double-check that 5707, 5782, and 5755 are indeed valid IDs for your agent custom post type (you mentioned they are, so this is just a quick sanity check!).

That's all you need to do—this should immediately remove those three agents from your query results.

内容的提问来源于stack exchange,提问作者Claudio Xerez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 19:32:32