Filter default 'post_type' array
I apologize for asking this here. I have looked over the https://docs.reduxframework.com/core/advanced/actions-hooks/, the sample-config.php and searched on stackoverflow and google can't find an answer to this.
All I need to do is find a way to filter out 'pages, media' from the default 'post_type', using a Redux action or filter.
thanks!
// Post Types
array(
'title' => __('Post Types', $i18n),
'subtitle' => __('Select which \'Post Types\' the plugin should target', $i18n),
'type' => 'select',
'id' => 'added_post_types',
'data' => 'post_type',
'multi' => true,
'default' => array('post'),
),
If you examine the select docs page, you'll not the field accepts an 'args' argument. It is with this argument you can filter your criteria based on the available argument for the post_type data type. See: https://codex.wordpress.org/Function_Reference/get_post_types.
I guess what I am after in a broader sense is how to use the built-in Redux hooks to filter field options, arguments before they are finally rendered.
redux/options/{opt_name}/field/{field.id}
// this doesn't seem to work or I don't understand how to use it.
add_filter('redux/options/' . $opt_name . '/select/added_post_types', 'get_custom_post_types' );
function get_custom_post_types($args) {
// Filter args here
return $args;
}
Your filter is wrong.
redux/options/' . $opt_name . '/field/added_post_types'
Only things in brackets need to be changed to the proper information. 'fields' stays the way it is.
Thanks, got it working but the filter returned the same data as Redux::getField($opt_name, $id)
Is there a Redux filter or action hook I can use to update the $data array 'data' => 'post_type', before rendering the field?
You can use your own custom data argument name to populate an array to use in the select field, but there is no post query altering of data beyond the method outlines by @kprovance.
Best bet is to just make a custom data key (or override an existing) and do it yourself. ;)
Thanks Kevin and Dovy
I added this apply_filter to framework.php line 989
$data = apply_filters( "redux/options/{$this->args['opt_name']}/data/$type/args", $data );
Then in 'options_init.php' I updated the args like this:
add_filter( "redux/options/".$opt_name."/data/post_type/args", 'update_post_types' );
function update_post_types($args) {
unset($args['page']);
unset($args['attachment']);
return $args;
}
Seems to be working well, do you see any issues with doing it this way, other than its not part of the core code?
Nope. That's why I put that filter in there. ;)
Cool man thanks again.