WPQuery Shortcode is a lightweight plugin that wraps the functionality of WP_Query in an easy-to-use shortcode.
Several filters are built in to allow all kinds of messing with how the output is displayed. From a simple "Recent Posts" block on your page to displaying upcoming events from your calendar plugin to showing the most visited job postings,
WPQuery Shortcode makes it easy.
Examples
The most basic example is this:
[wqs][/wqs]
Which returns the following HTML by default:
+-- -
| Title One
| 5x
|
This is the excerpt text.
|
+--
If you want to use a
section
tag instead of a
div
tag, use the following filters to override the defaults:
function wqs_wrapper_start($class) {
return "
";
}
WQSDefaults::remove_filter('wqs_wrapper_start'); // Removes the default filter
add_filter('wqs_wrapper_start', 'wqs_wrapper_start');
function wqs_wrapper_end() {
return "";
}
WQSDefaults::remove_filter('wqs_wrapper_end'); // Removes the default filter
add_filter('wqs_wrapper_end', 'wqs_wrapper_end');
If you want to use the plugin within another plugin or directly from your
functions.php
file in order to save yourself some trouble with The Loop:
WQSDefaults::remove_all_filters(); // Removes all default filters
// Add your own filters here.
$wqs = WQS::get_instance();
$items = $wqs->wqs(array(
'cat' => 3,
// More WP_Query parameters here
), 'Some header text here', TRUE); // Third param returns an array instead of a string.
foreach ($items as $id => $item) {
// do stuff
}