return $result[$k]; if (3 == DEBUG) return TRUE; if (1 == $gid) return TRUE; // 管理员有所有权限 if (!isset($grouplist[$gid])) return TRUE; $group = $grouplist[$gid]; $result[$k] = empty($group[$access]) ? FALSE : TRUE; return $result[$k]; } // 从缓存中读取 forum_list 数据 function group_list_cache() { global $conf; if ('mysql' == $conf['cache']['type']) { $grouplist = group_get(); } else { $grouplist = cache_get('grouplist'); if (NULL === $grouplist || FALSE === $grouplist) { $grouplist = group_find(); cache_set('grouplist', $grouplist); } } return $grouplist; } // 更新 forumlist 缓存 function group_list_cache_delete() { global $conf; $r = 'mysql' == $conf['cache']['type'] ? group_delete_cache() : cache_delete('grouplist'); return $r; } //--------------------------kv + cache-------------------------- $g_grouplist = FALSE; function group_get() { global $g_grouplist; FALSE === $g_grouplist AND $g_grouplist = website_get('grouplist'); if (empty($g_grouplist)) { $g_grouplist = group_find(); $g_grouplist AND group_set($g_grouplist); } return $g_grouplist; } function group_set($val) { global $g_grouplist; $g_grouplist = $val; return website_set('grouplist', $g_grouplist); } function group_delete_cache() { website_set('grouplist', ''); return TRUE; } ?>customization - Getting 404 on child page with pre_get_posts() on custom posts|Concepts Of Algorithm

customization - Getting 404 on child page with pre_get_posts() on custom posts

admin2025-06-05  4

I want to have custom taxonomy for publishing different type of posts. I have registered several custom posts like with the code below

function wtp_case_studies() {

    $labels = array(
        'name'                  => _x( 'Case Studies', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'Case Studies', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Case Studies', 'text_domain' ),
        'name_admin_bar'        => __( 'Edit Team', 'text_domain' ),
        'archives'              => __( 'Аrchive', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
        'all_items'             => __( 'All Case Studies', 'text_domain' ),
        'add_new_item'          => __( 'Add New Case Study', 'text_domain' ),
        'add_new'               => __( 'Add New Case Study', 'text_domain' ),
        'new_item'              => __( 'New Case Study', 'text_domain' ),
        'edit_item'             => __( 'Edit Case Study', 'text_domain' ),
        'update_item'           => __( 'Update Case Study', 'text_domain' ),
        'view_item'             => __( 'View Case Study', 'text_domain' ),
        'search_items'          => __( 'Search', 'text_domain' ),
        'not_found'             => __( 'Not Found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not Found', 'text_domain' ),
        'featured_image'        => __( 'Featured Image', 'text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
        'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
        'items_list'            => __( 'List of Cards', 'text_domain' ),
        'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'Management Profiles', 'text_domain' ),
        'description'           => __( 'anagement Profiles', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title','thumbnail',  'page-attributes'),
        'hierarchical'          => true,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-megaphone',
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,        
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
        //'rewrite'                 => array('slug' => 'case-studies')
        'rewrite'               => array('slug' => '/','with_front' => false,'pages'=> true,'feeds'=>true)
    );
    register_post_type( 'casestudies', $args );

}

This code allows me to create Case Studies taxonomy and to access them directly via its slug (for example /my_new_case_study/), without the prefix (not like /case-studies/my_new_case_study/). To be able to access those posts in Case Studies I am using this function

function gp_add_cpt_post_names_to_main_query( $query ) {
    if ( ! $query->is_main_query() ) {
        return;
    }
    if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
        return;
    }
    if ( empty( $query->query['name'] ) ) {
        return;
    }
    $query->set( 'post_type', array( 'post', 'page','casestudies') );
}
add_action( 'pre_get_posts', 'gp_add_cpt_post_names_to_main_query' );

Now when I create new regular post or page called "my_new_post" with the parent "my_old_post", my new slug is /my_old_post/my_new_post/ displayed in the dashboard, but when I click on it I get 404 message. If I remove "pre_get_posts" then I can access that page, but I can't access case studies posts. How can I access both hierarchy pages and new custom post "casestudies"?

I have flushed permalinks a number of times and tested everything.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749076766a316157.html

最新回复(0)