wpgb_render_template
This function allows to query and output posts, terms, or users with your own markup without the grid and card system. You will be able with this function to use the facet system as stand alone (thanks to wpgb_render_facet()
function) without creating grids or cards.
Argument | Type | Description |
id | mixed | Template id/name |
class | string | Class name of the layout wrapper holding posts |
source_type | string | Object type to query (post_type, term, user) |
is_main_query | boolean | To replace loop in archive/index/search.php templates |
query_args | array | Holds query arguments |
render_callback | string | Function name of the render callback |
noresults_callback | string | Function name of the no results callback |
You can add this function anywhere in your PHP file to output a filterable template. This function can also replace the main loop of the archive.php
, index.php
or search.php
files. In this case you need to set is_main_query
to true
If you set is_main_query
to true
query_args
parameter will be ignored because it’s handle by WordPress template.
[pastacode lang=”php” manual=”wpgb_render_template(%0A%09%5B%0A%09%09’id’%20%3D%3E%20’my-template’%2C%0A%09%09’class’%20%3D%3E%20”%2C%0A%09%09’source_type’%20%3D%3E%20’post_type’%2C%0A%09%09’is_main_query’%20%3D%3E%20false%2C%0A%09%09’query_args’%20%3D%3E%20%5B%0A%09%09%09’post_type’%20%3D%3E%20’product’%2C%0A%09%09%09’posts_per_page’%20%3D%3E%2010%2C%0A%09%09%5D%2C%0A%09%09’render_callback’%20%3D%3E%20’prefix_render_callback’%2C%0A%09%09’noresults_callback’%20%3D%3E%20’prefix_noresults_callback’%2C%20%0A%09%5D%0A)%3B” message=”” highlight=”” provider=”manual”/]
The callback functions must be placed in functions.php or in a plugin file for example. The facet system will not load the PHP file where you placed the function wpgb_render_template()
for performance reason. For this reason the callback must be a string (function name) and not the function itself.
[pastacode lang=”php” manual=”%3C%3Fphp%0A%0A%2F**%0A*%20This%20callback%20is%20called%20for%20each%20post%20in%20the%20loop.%0A*%0A*%20%40param%20object%20%24post%20Holds%20post%2C%20term%20or%20user%20object%20(depending%20of%20the%20source_type).%20%0A*%2F%0Afunction%20prefix_render_callback(%20%24post%20)%20%7B%0A%0A%09%3F%3E%20%0A%09%3Carticle%3E%0A%09%09%3C%3Fphp%20the_title(%20’%3Ch3%3E’%2C%20’%3C%2Fh3%3E’%20)%3B%20%3F%3E%0A%09%09%3C%3Fphp%20the_excerpt()%3B%20%3F%3E%20%0A%09%3C%2Farticle%3E%0A%09%3C%3Fphp%0A%0A%7D%0A%0A%2F**%0A*%20This%20callback%20is%20called%20when%20no%20results%20match%20selected%20facets.%20%0A*%2F%0Afunction%20prefix_noresults_callback()%20%7B%0A%0A%09%3F%3E%0A%09%3Cp%3E%0A%09%3C%3Fphp%20esc_html_e(%20’Sorry%2C%20no%20results%20match%20your%20search%20criteria.’%2C%20’text-domain’%20)%3B%20%3F%3E%3C%2Fp%3E%0A%0A%09%3C%3Fphp%0A%7D” message=”” highlight=”” provider=”manual”/]