Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filter Nooz posts by custom-field values
<?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
You can’t perform that action at this time.