Skip to main content
All CollectionsDynamic ShortcodesFeaturesAdvanced Features
Literal (lit) Dynamic Shortcode, for expressing PHP values Null, True and False
Literal (lit) Dynamic Shortcode, for expressing PHP values Null, True and False
Updated over 6 months ago

In some situations you need to use the PHP values Null, True and False.

In a filter for example, you might have a function that requires them as arguments. You can do this with the lit Dynamic Shortcode.

You simply pass the value name as the first argument:
โ€‹

  • {lit:true} for True

  • {lit:false} for False

  • {lit:null} for Null

Using Literal Values in Post Queries

In this example, we demonstrate how to use the lit Dynamic Shortcode to express PHP values Null, True, and False, which can be used as part of a query to dynamically filter posts.

Practical Example: Filtering Posts with Specific Values

Suppose you want to retrieve posts based on a custom field that can be true or false. For example, you might want to show only posts that are marked as "important" in a custom post field.

{query:posts @meta_key=important meta_value={lit:true}}


In this case, {lit:true} is used to pass a literal true value to the query, ensuring that the query looks for posts with the 'important' meta field set to true.

Explanation:

  • {lit:true}: This literal shortcode returns the Boolean value true, which is used as the value for meta_value in the post query.

  • @meta_key and @meta_value: These arguments specify that we want to filter posts that have a meta field called 'important' with a value of true.

Alternative Usage

You can also use {lit:false}, {lit:true} or {lit:null} to achieve different behaviors, depending on the specific filtering needs:

  • To exclude posts: Suppose you want to exclude posts that are less important

    {query:posts @meta_key=important meta_value={lit:false}}

  • To include posts without a specified value: If you want to include posts where the 'important' field has not been set:

    {query:posts @meta_key=important meta_value={lit:null}}

Why it is important to use literal values

When using literal values such as true, false, or null directly in Dynamic Shortcodes without the lit prefix, they would be treated as strings rather than their intended Boolean or null values.

This is critical because the query system interprets strings differently from Boolean values and null, which could lead to unexpected results.

For example:

{query:posts @meta_key=important meta_value=true}

In the above line, true without {lit:true} is treated as the string 'true', which means it would look for posts where the 'important' meta field contains the string "true", not where it is logically true.

Similarly, using:

{query:posts @meta_key=important meta_value=false}

Here, false is treated as the string 'false', and the query would search for posts where the 'important' meta field contains the string "false", not where it is logically false.

And for null:

{query:posts @meta_key=important meta_value=null}

Without using {lit:null}, null is treated as the string 'null', not as an actual null value, which might not produce the intended effect of including posts with an unset or null 'important' field.

Did this answer your question?