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:
Name | Value |
---|---|
current_post | Returns the current post ID |
current_term | Returns the current term id when used on an taxonomy archive. |
current_author | Returns the current post author id. |
current_user | Returns the current logged in user id. |
today | Returns the date using the format ‘Ymd’. |
gt | Returns the greater than operator “>”. |
gte | Returns the greater than or equal operator “>=”. |
lt | Returns the less than “<“. |
lte | Returns the less than or equal operator “<=”. |
related | Add related=1 to your query to display related items. |
featured | Add 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;
} );