Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Created June 17, 2014 01:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfmeier/05cbcac534847bff3046 to your computer and use it in GitHub Desktop.
Save rfmeier/05cbcac534847bff3046 to your computer and use it in GitHub Desktop.
Display a Genesis custom loop within a shortcode.
<?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