WPQuery Shortcode

A shortcode wrapper for WP_Query.

Author:Russ Porosky (profile at wordpress.org)
WordPress version required:3.5
WordPress version tested:3.8
Plugin version:1.1.2
Added to WordPress repository:15-09-2013
Last updated:13-12-2013
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
Rating, %:0
Rated by:0
Plugin URI:http://indyarmy.com/wpquery-shortcode/
Total downloads:738
Active installs:10+
plugin download
Click to start download

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:

<div class="wqs_list">
    <ul class="wqs_list_post_wrap">
+--     <li class="wqs_list_post_item">
|           <a href="…" class="wqs_title">Title One</a>
| 5x        <span class="wqs_list_wqs_excerpt">
|               <p>This is the excerpt text.</p>
|           </span>
+--     </li>
    </ul>
</div>

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 "<section class=\"{$class}\">";
}
WQSDefaults::remove_filter('wqs_wrapper_start');        // Removes the default filter
add_filter('wqs_wrapper_start', 'wqs_wrapper_start');

function wqs_wrapper_end() {
    return "</section>";
}
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
}