Created
May 10, 2019 03:54
-
-
Save farinspace/6046bd9c5ab9e1acaef63d4c9db0344c to your computer and use it in GitHub Desktop.
Filter Nooz posts by custom-field values
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 | |
/** | |
* The solution below allows you to filter Nooz posts by custom-field values. | |
* | |
* 1. Enable support for "custom-fields" | |
* 2. Add a custom field variable to a press release post, in the example below, the variable is "lang_type" | |
* 3. Use the "class" attribute to determine which shortcode instance gets filtered, in the example below, shortcodes using "class='lang-es'" | |
*/ | |
/** | |
* Add support for "custom-fields" to the "nooz_release" post type. | |
*/ | |
add_filter( 'nooz/post-types/nooz_release/options', function( $args ) { | |
$args['supports'][] = 'custom-fields'; | |
return $args; | |
} ); | |
/** | |
* Check for shortcodes using "class='lang-es'" and filter posts. | |
*/ | |
add_filter( 'nooz_posts_query_options', function( $query_options, $atts ) { | |
if ( FALSE !== strpos( $atts['class'], 'lang-es' ) ) { | |
$query_options['meta_key'] = 'lang_type'; | |
$query_options['meta_value'] = 'es'; | |
} | |
return $query_options; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment