Skip to content

Instantly share code, notes, and snippets.

@farinspace
Created May 10, 2019 03:54
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 farinspace/6046bd9c5ab9e1acaef63d4c9db0344c to your computer and use it in GitHub Desktop.
Save farinspace/6046bd9c5ab9e1acaef63d4c9db0344c to your computer and use it in GitHub Desktop.
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