Skip to content
🎉

Cyber Sale Blowout! Get 50% OFF — Limited Time Only!

Click to Save 50% (opens in a new tab)

Using Dynamic Strings (values) in Advanced Queries

In this article

    When working with the “Advanced Query” setting in various Total modules it’s possible to use certain strings to return dynamic values. The following are available:

    NameValue
    current_postReturns the current post ID
    current_termReturns the current term id when used on an taxonomy archive.
    current_authorReturns the current post author id.
    current_userReturns the current logged in user id.
    todayReturns the date using the format ‘Ymd’.
    gtReturns the greater than operator “>”.
    gteReturns the greater than or equal operator “>=”.
    ltReturns the less than “<“.
    lteReturns the less than or equal operator “<=”.
    relatedAdd related=1 to your query to display related items.
    featuredAdd featured=1 to your WooCommerce products query to display featured items.

    Sample Usage

    Check out some examples on how you can use the dynamic strings in your advanced queries.

    Exclude current post from Query

    post_type=post&posts_per_page=10&post__not_in=current_post

    Display Items from the same author:

    post_type=post&posts_per_page=10&author__in=current_author

    Hide any “past” items based on a date custom field.

    If you are using a custom post type that has an event you can easily write a query to exclude “past” items by using a meta_query setting the key to your custom field name, the value to “today” and the compare argument to “gte”. In other words we are telling WordPress to get any posts where the date is greater than or equal to today.

    post_type=post&posts_per_page=10&meta_query[0][key]=date&meta_query[0][value]=today&meta_query[0][compare]=gte
    Important: Your date field must use the WordPress compatible date format date( ‘Ymd’ ). This is the format needed to query posts based on a date and is used by popular plugins such as Events Calendar and is the date format used for the theme’s WPEX_Meta_Factory class used for adding custom fields to the theme.

    Adding Your Own Dynamic Strings

    If you wish to register your own dynamic strings it’s possible by hooking into “vcex_grid_advanced_query_dynamic_values”, below is an example:

    add_filter( 'vcex_grid_advanced_query_dynamic_values', function( $strings ) {
        $strings['current_time'] = current_time( 'timestamp' );
        return $strings;
    } );
    Related Articles
    Back To Top