Skip to main content

How to Set Up Meta Query in Posts Query

Meta Query allows you to filter and display posts based on the values stored in their meta fields. You set a target value, and the data from the chosen meta field is compared to it. If they match, the post is included in the results.

Updated over 8 months ago

1. Meta Query Fields Explanation

  • Field key/name – Enter the meta field name attached to your chosen Post Type. You can also use Dynamic Tags to customize the value with Context and Fallback settings if needed.

  • Value – The target value to compare against the meta field’s value.

  • Compare – Select how the values will be compared:

    • Equal – Displays posts with an equal value.

    • Not Equal – Shows posts with a different value.

    • Greater than / Greater or equal – Works with numeric values only.

    • Less than / Less or equal – For numeric values only.

    • Like – Finds partial matches.

    • In the list / Not in the list – Filters based on multiple values.

    • Between / Not between – Filters within or outside a range of values.

    • Exist / Not exist – Checks if the meta key exists.

    • Regexp / Not regexp – Used for Checkbox or Radio meta field values.

  • Type – Specify the data type of the meta field:

    • Char – Alphabetic data (case-insensitive).

    • Numeric – Whole numbers.

    • Date / Datetime – Date or time values.

    • Decimal – Fractional numbers.

    • Time – Time values.

    • Signed / Unsigned – Whole numbers (positive or both positive and negative).

  • Clause name – Assign a unique name to the clause if you want to sort posts using it.


2. Use Cases and Examples

2.1 Query by Checkbox/Select/Radio Meta Field

  1. Ensure “Save as array” is enabled if it's Checkbox meta field. (If not - enable it first and then resave posts with new values)

  2. In Field key/name, select your metafield with macros “JetEngine meta field” and return the Field name/key/ID.

  3. Set the Compare operator:

    • Like for Checkbox or multiple Select fields.

    • Equal for non-multiple Select or Radio fields.

  4. Enter the desired value in the Value field.

2.2 Query by Media Meta Field

To check if a post has a file attached in the meta field:

  1. Use “JetEngine meta field” and return the Field name/key/ID.

  2. Set Compare to “Greater than” and the Value to 0.

2.3 Query by Date Meta Field

Example: Display posts starting after specific static date.

Note: Works only if your date meta field is saved as a Timestamp.

  1. Add this code to your child theme’s functions.php or use the Code Snippets plugin: Code Link

  2. Configure Meta Query:

    • Field key/name: “JetEngine meta field”

    • Compare: “Greater or equal” and Type - "Numeric"

    • Value: Use “Format Date String” with these settings:

      • Format: U (for Timestamp)

      • Date String: Enter your static date.

      • Show by: Server Time

2.4 Query by Text Meta Field

Example: In a text meta field, you can add a date in the d.m. format (e.g., 01.12) to display posts annually on the same day and month specified in the meta field.

  1. In Field key/name, use “JetEngine meta field”.

  2. Set Compare to Equal.

  3. Use “Current Date” macro with format d.m. for the Value field.


3. Advanced Query Example – Compare Meta Field with Current User Email

To filter posts where the current user’s email matches a text meta field:

  1. In Field key/name, select “JetEngine meta field” and choose your meta field.

  2. Set Compare to Equal.

  3. Create a shortcode for the user’s email using the Shortcode Generator.

  4. Use “Shortcode Result” macro as the Value.

Did this answer your question?