Skip to content

Instantly share code, notes, and snippets.

@robincornett

robincornett/functions.php Secret

Created Aug 26, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.