Custom Query Shortcode
This plugin gives you [query] shortcode which enables you to query and output any posts filtered by specific attributes. Usage You can use most parameters supported by WP_Query class to filter the posts; you can query for specific post types, categories, tags, authors, etc. Other supported parameter
This plugin gives you [query] shortcode which enables you to query and output any posts filtered by specific attributes.
Usage
You can use most parameters supported by WP_Query class to filter the posts; you can query for specific post types, categories, tags, authors, etc.
Other supported parameters
Aside from WP_Query parameters, the shortcode also supports the following additional parameters:
- featured : to query for sticky posts which by default are excluded from the query.
- thumbnail_size : to specify the size of the {THUMBNAIL} images. You can use built-in image sizes or custom ones you’ve defined.
- content_limit : to limit the number of words of the {CONTENT} var; by default it’s “0” which means it outputs the whole content.
- posts_separator : text to display between individual posts.
- lens : custom output template – see description below.
- twig_template : output template using Twig templating engine – requires the Timber library.
Formatting the output
You can define how you want to format the output inline within an opening [query] and closing [/query] tag. Available keywords are: TITLE, CONTENT, AUTHOR, AUTHOR_URL, DATE, THUMBNAIL, CONTENT, COMMENT_COUNT.
The following example will display the latest 5 posts from the category with the ID of 3, showing a post title and comment count, with a link to the post: [query posts_per_page=”5″ cat=”3″]
{TITLE} ({COMMENT_COUNT})
[/query]
Grid display
With the “cols” parameter you can display the output in a grid. [query posts_per_page=”3″ cols=”3″] {THUMBNAIL}
{TITLE}
{CONTENT} [/query] will display the latest 3 posts in the defined template, in 3 columns. The plugin will automatically divide the grid into rows based upon the ‘posts_per_page’ option, divided by the ‘cols’ option.
Lenses (output templates)
With the “lens” parameter you can customize the display of the query results using a template. Some basic lenses/templates are provided:
- ul : unordered list of linked post titles.