Skip to content

Table Query

The Table Query node fetches rows from a WP-Nexus custom database table. It is the most common source node for apps that use custom tables.

Configuration

PropertyTypeDefaultDescription
tableIdnumber--Required. The ID of the WP-Nexus database table to query.
orderBystringidColumn name to sort by.
orderstringDESCSort direction: ASC or DESC.
conditionsarray[]Array of condition objects (see Conditions below).
conditionLogicstringANDHow multiple conditions combine: AND (all must match) or OR (any must match).
limitnumber100Maximum number of rows to return (capped at 1,000).
offsetnumber0Number of rows to skip before returning results.

Legacy single-condition properties

These flat properties still work for backward compatibility. If conditions is present, it takes precedence.

PropertyTypeDefaultDescription
whereFieldstring--Column name to filter on.
whereOpstring=Comparison operator.
whereValuestring--Value to compare against.

Input

This is a source node -- it has no input port. It always produces data from scratch.

Output

Returns an array of row objects. Each row is an associative array with column names as keys.

json
[
  { "id": 1, "title": "First item", "status": "active", "created_at": "2025-03-01 10:00:00" },
  { "id": 2, "title": "Second item", "status": "draft", "created_at": "2025-03-02 14:30:00" }
]

How It Works

For custom tables (the default storage type), the node builds a native SQL query with WHERE, ORDER BY, LIMIT, and OFFSET clauses. This means filtering and sorting happen at the database level for optimal performance.

For tables backed by Custom Post Types or Taxonomies, the node uses WP_Query or get_terms() respectively, then applies query options in PHP as a fallback.

Conditions

The Table Query node supports multiple WHERE conditions with AND/OR logic. In the UI, each condition is a row with a field name, operator, and value. Click Add condition to add more rows, or the remove button to delete one.

AND / OR toggle

When you have two or more conditions, an AND/OR toggle appears. Choose AND to require all conditions to match, or OR to match rows where any condition is true. The default is AND.

Field autocomplete

The field name input suggests column names from the selected table's schema. When you pick a table, its columns are fetched automatically and offered as autocomplete suggestions. You can also type any field name manually -- the input accepts free text.

Operators

OperatorDescriptionExample SQL
=EqualWHERE status = 'active'
!=Not equalWHERE status != 'draft'
>Greater thanWHERE price > 100
<Less thanWHERE price < 50
>=Greater than or equalWHERE price >= 10
<=Less than or equalWHERE price <= 99
LIKEPartial match (wraps value in %)WHERE title LIKE '%search%'
BETWEENBetween two values (inclusive)WHERE price BETWEEN 10 AND 50
INMatches any value in a listWHERE status IN ('active', 'pending')
NOT INDoes not match any value in a listWHERE status NOT IN ('draft', 'trash')
IS NULLValue is nullWHERE deleted_at IS NULL
IS NOT NULLValue is not nullWHERE email IS NOT NULL

Operator-specific inputs

  • BETWEEN: Shows two value fields. Enter the lower bound in the first and the upper bound in the second.
  • IN / NOT IN: Enter values as a comma-separated list (e.g., active, pending, review). Each value is individually escaped.
  • IS NULL / IS NOT NULL: No value field is shown -- these operators test for the presence or absence of a value.

All values are escaped using $wpdb->prepare() to prevent SQL injection.

Dynamic Config with Expressions

Condition values support { { }} expressions. This lets you build dynamic queries based on upstream data:

conditions:
  - field: "user_id"
    op: "="
    value: "{{ input.id }}"

Example Use Cases

Basic: List all active products

tableId: 3
conditions:
  - field: "status"
    op: "="
    value: "active"
conditionLogic: "AND"
orderBy: "created_at"
order: "DESC"
limit: 50

Multiple conditions with AND logic

tableId: 3
conditions:
  - field: "status"
    op: "="
    value: "active"
  - field: "price"
    op: "BETWEEN"
    value: "10"
    value2: "100"
conditionLogic: "AND"
orderBy: "price"
order: "ASC"

Multiple conditions with OR logic

tableId: 3
conditions:
  - field: "category"
    op: "="
    value: "electronics"
  - field: "category"
    op: "="
    value: "accessories"
conditionLogic: "OR"

IN operator with comma-separated values

tableId: 3
conditions:
  - field: "status"
    op: "IN"
    value: "active, pending, review"

IS NULL to find missing data

tableId: 3
conditions:
  - field: "deleted_at"
    op: "IS NULL"

Paginated listing

tableId: 3
orderBy: "title"
order: "ASC"
limit: 10
offset: 20

Dynamic: Show orders for a specific user

Connect a Current User node upstream, then use its output in the config:

tableId: 5
conditions:
  - field: "user_id"
    op: "="
    value: "{{ input.id }}"
orderBy: "created_at"
order: "DESC"

TIP

For the best performance, add database indexes to columns you frequently filter or sort on. You can configure indexes in the WP-Nexus table editor.