Post List Query Usage

 When using the post list attribute the settings for filters for the post list will show under a new section called posts query in the widget edit mode.

This is an overview of the fields in post query. You can filter your query by two types of post sources using the dropdown.

Custom Posts - Will filter the post list by all the visible populated settings

  • Post Type - Page, Field Group, Field, Template or any Custom Post Type you have created.
  • Include by Term - Choose one or more terms to filter your post list. If no terms are chosen all the posts from the post type selected will be chosen. 
  • Exclude by - Gives you the option to exclude the current post from the list. (More options coming soon...)
  • Max Posts - Determines the maximum number of posts shown in the list. If left empty will show all posts 
  • Order by: Determines the the order of the posts. You can also select to order by custom fields you have created by selecting order by custom field value.

Current Query Posts - This type works only when the widget is inside of an archive template. It shows the current posts which are being used in the archive page.

To create custom filters not available in the settings using php code. You can assign the post list a Query ID (this feature is only available in the the pro version of unlimited elements)
Using the Query ID feature you have unlimited possibilities to select your posts.

Instructions how to use the query ID filter: 

In the widget you set the query ID to my_query_filter

after that you go to your theme folder - functions.php file and add those lines:

/*
 * filter the arguments to get my custom posts
 * args - original arguments
 * $widgetControlsValues - all the values of the current widget. 
 * it can be used for the post list
 */
function myQueryFilter($args, $widgetControlsValues){
	
	//set filter to posts that published within 24 hours (today)
	$args['date_query'] = array(
	        'column'  => 'post_date',
	        'after'   => '-1 days'
	 );
					
	return($args);
}

add_filter("my_query_filter", "myQueryFilter", 10, 2); 

Another code example, with use of $widgetControlValues. For this example you create a dropdown attribute with those settings: 

Name: day, values: all, today, tomorrow. What we want is that if today chosen, it will filter posts only from today, and if yesterday chosen, it will filter posts from yesterday. So in functions.php you insert this code: 

/**
 * filter the arguments to get my custom posts
 * args - original arguments
 * $widgetControlsValues - all the values of the current widget. 
 * it can be used for the post list
 */
function myQueryFilter($args, $widgetControlsValues){
		
	$day = $widgetControlsValues["day"];
	
	if($day == "today"){
		$args['date_query'] = array(
	        'column'  => 'post_date',
	        'after'   => '-1 days'
	    );				
	    
	}
	else
	if($day == "yesterday"){
		
		$args['date_query'] = array(
	        'column'  => 'post_date',
	        'after'   => '-2 days',
		'before'  => '-1 days'
	    );		
	}
	
	
	return($args);
}
add_filter("my_query_filter", "myQueryFilter", 10, 2);

Of cause, you don't have to put your code into functions.php, there are certain plugins that you can put php code snippets into it without updating theme php files. 

Plugin example: https://wordpress.org/plugins/code-snippets/

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.