Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Warning: foreach() argument must be of type array|object, string given in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 813
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
PUM_ConditionCallbacks::post_type( array $condition = array() )
Checks if this is one of the selected post_type items.
Description Description
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Warning: foreach() argument must be of type array|object, string given in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 813
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Parameters Parameters
- $condition
-
(Optional)
Default value: array()
Return Return
(bool)
Source Source
File: classes/ConditionCallbacks.php
public static function post_type( $condition = array() ) { global $post; $target = explode( '_', $condition['target'] ); // Modifier should be the last key. $modifier = array_pop( $target ); // Post type is the remaining keys combined. $post_type = implode( '_', $target ); $selected = ! empty( $condition['settings']['selected'] ) ? $condition['settings']['selected'] : array(); switch ( $modifier ) { case 'index': if ( is_post_type_archive( $post_type ) ) { return true; } break; case 'all': // Checks for valid post type, if $post_type is page, then include the front page as most users simply expect this. if ( self::is_post_type( $post_type ) || ( $post_type == 'page' && is_front_page() ) ) { return true; } break; case 'ID': case 'selected': if ( self::is_post_type( $post_type ) && is_singular( $post_type ) && in_array( $post->ID, wp_parse_id_list( $selected ) ) ) { return true; } break; case 'children': if ( ! is_post_type_hierarchical( $post_type ) || ! is_singular( $post_type ) ) { return false; } // Chosen parents. $selected = wp_parse_id_list( $selected ); foreach ( $selected as $id ) { if ( $post->post_parent == $id ) { return true; } } break; case 'ancestors': if ( ! is_post_type_hierarchical( $post_type ) || ! is_singular( $post_type ) ) { return false; } // Ancestors of the current page. $ancestors = get_post_ancestors( $post->ID ); // Chosen parent/grandparents. $selected = wp_parse_id_list( $selected ); foreach ( $selected as $id ) { if ( in_array( $id, $ancestors ) ) { return true; } } break; case 'template': if ( is_page() && is_page_template( $selected ) ) { return true; } break; } return false; }
Expand full source code Collapse full source code View on Trac