Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created August 26, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robincornett/5cb97b6068787807830fe3f1cca64c7c to your computer and use it in GitHub Desktop.
Save robincornett/5cb97b6068787807830fe3f1cca64c7c to your computer and use it in GitHub Desktop.
Examples for changing the query args on a Six/Ten Press Featured Content widget.
<?php
add_filter( 'sixtenpressfeaturedcontent_query_args', 'prefix_modify_widget_query', 10, 2 );
/**
* Set a custom order on the widget output.
* Outputs retreats for https://thesoulcareproject.org/ starting with the next upcoming retreat.
* @param $query_args
* @param $instance
*
* @return mixed
*/
function prefix_modify_widget_query( $query_args, $instance ) {
if ( 'retreat' === $instance['post_type'] ) {
$query_args['orderby'] = 'meta_value post_date';
$query_args['meta_key'] = '_retreats_start_date';
$query_args['meta_value'] = strtotime( date( 'Ymd' ) );
$query_args['meta_compare'] = '>=';
$query_args['order'] = 'ASC';
}
return $query_args;
}
add_filter( 'sixtenpressfeaturedcontent_query_args', 'prefix_show_parent_posts', 10, 2 );
/**
* For a ministry custom post type which allows child posts/pages, make sure the
* widget only shows top level posts/ministries.
* @param $query_args
* @param $instance
*
* @return mixed
*/
function prefix_show_parent_posts( $query_args, $instance ) {
if ( 'ministry' !== $instance['post_type'] ) {
return $query_args;
}
$query_args['post_parent'] = 0;
return $query_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment