_wp_preview_terms_filter()
Filters terms lookup to set the post format.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
Array.
Usage
_wp_preview_terms_filter( $terms, $post_id, $taxonomy );
- $terms(array) (required)
- .
- $post_id(int) (required)
- .
- $taxonomy(string) (required)
- .
Changelog
| Since 3.6.0 | Introduced. |
_wp_preview_terms_filter() wp preview terms filter code WP 7.0
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
$post = get_post();
if ( ! $post ) {
return $terms;
}
if ( empty( $_REQUEST['post_format'] ) || $post->ID !== $post_id
|| 'post_format' !== $taxonomy || 'revision' === $post->post_type
) {
return $terms;
}
if ( 'standard' === $_REQUEST['post_format'] ) {
$terms = array();
} else {
$term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' );
if ( $term ) {
$terms = array( $term ); // Can only have one post format.
}
}
return $terms;
}