Created
June 17, 2014 01:44
-
-
Save rfmeier/05cbcac534847bff3046 to your computer and use it in GitHub Desktop.
Display a Genesis custom loop within a shortcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('init' , 'jspt_init'); | |
/** | |
* Callback for WordPress 'init' action. | |
* | |
* Reigster the custom shortcode. | |
* | |
* @return void | |
*/ | |
function jspt_init() { | |
add_shortcode( 'jssd-in-memoriam', 'jspt_memoriam_shortcode_handler' ); | |
} | |
/** | |
* Callback for WordPress add_shortcode() function. | |
* | |
* @param attay $atts The shortcode attributes. | |
* @return string The shortcode output. | |
*/ | |
function jspt_memoriam_shortcode_handler( $atts ) { | |
extract( | |
shortcode_atts( | |
array('ffld' => false), | |
$atts | |
) | |
); | |
if ( $ffld === false ) | |
return 'You must specify ffld="yes" or ffld="no" with in the shortcode.'; | |
$args = array ( | |
'post_status' => 'publish', | |
'post_type' => 'memoriam', | |
'posts_per_page' => -1, // Unlimited posts per page | |
'meta_key' => 'wpcf-deceased-date', | |
'orderby' => 'meta_value_num', // Order by Deceased Date | |
'order' => 'DESC', | |
'meta_query' => array( | |
array( | |
'key' => 'wpcf-firefighter-line-of-duty', // Firefighters Line of Duty only | |
'value' => $ffld, // yes or no | |
'compare' => 'IN' | |
) | |
) | |
); | |
ob_start(); | |
genesis_custom_loop( $args ); | |
$html = ob_get_clean(); | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment