Skip to content

Post Query

The Post Query node fetches WordPress posts, pages, or custom post types using WP_Query. Use it when your data is stored as WordPress posts rather than custom database tables.

Configuration

PropertyTypeDefaultDescription
postTypestringpostThe post type slug (e.g., post, page, product, or a WP-Nexus CPT like nxs_mytype).
statusstringpublishPost status filter: publish, draft, pending, private, any.
orderBystringdateField to sort by: title, date, ID, modified, rand, name, author, or any meta key.
orderstringDESCSort direction: ASC or DESC.
conditionsarray[]Array of condition objects. Each has field, op, value, and optionally value2 (for BETWEEN). See Table Query: Conditions for full details.
conditionLogicstringANDHow multiple conditions combine: AND or OR.
limitnumber100Maximum posts to return (capped at 1,000).
offsetnumber0Number of posts to skip.

Input

This is a source node -- it has no input port.

Output

Returns an array of post objects with both core fields and all post meta flattened into each row:

json
[
  {
    "ID": 42,
    "post_title": "Hello World",
    "post_content": "<p>Welcome to my site.</p>",
    "post_excerpt": "",
    "post_status": "publish",
    "post_date": "2025-03-15 09:00:00",
    "post_author": "1",
    "featured_image": "https://example.com/image.jpg",
    "custom_field": "some value"
  }
]

How It Works

The node builds a WP_Query arguments array and executes the query. For each returned post, it:

  1. Extracts core post fields (ID, post_title, post_content, post_excerpt, post_status, post_date, post_author).
  2. Fetches all post meta via get_post_meta() and merges it into the row at the top level.

Order By Meta Keys

When orderBy is set to a value that does not match a core field (e.g., price, rating), the node automatically sets meta_key and uses meta_value ordering. For known numeric field names (price, count, quantity, amount, rating, order), it uses meta_value_num for correct numeric sorting.

TIP

This node supports the enhanced conditions system with multiple conditions, AND/OR logic, and operators like BETWEEN, IN, NOT IN, IS NULL, and IS NOT NULL. See the Table Query: Conditions documentation for full details. Legacy single-condition properties (whereField, whereOp, whereValue) still work for backward compatibility.

WHERE Filtering

Filtering behavior depends on the field type:

  • post_title with LIKE: Uses the s (search) parameter of WP_Query.
  • post_author: Filters by author ID.
  • post_status: Overrides the status config.
  • Any other field: Creates a meta_query with the specified comparison operator.

Example Use Cases

List published blog posts

postType: "post"
status: "publish"
orderBy: "date"
order: "DESC"
limit: 10

Filter products by price range

postType: "product"
status: "publish"
whereField: "price"
whereOp: ">="
whereValue: "50"
orderBy: "price"
order: "ASC"

Search posts by title

postType: "post"
whereField: "post_title"
whereOp: "LIKE"
whereValue: "tutorial"

TIP

If your data does not need WordPress post features (revisions, taxonomies, featured images), consider using a custom database table instead. Custom tables are faster and produce simpler row structures.