$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>walker - Walker_Category - not reliably saving|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

walker - Walker_Category - not reliably saving

matteradmin8PV0评论

I'm currently creating a custom Walker_Category class to make some changes to how category selection works in a custom taxonomy. The taxonomy is called 'page_category'. I want to put this in a normal context metabox, so I've written the following:

class Walker_Smartcat extends Walker_Category {

}


function custom_check() {

    $args = array(
        'descendants_and_self'  => 0,
        'selected_cats'         => false,
        'popular_cats'          => false,
        'walker'                => 'Walker_Smartcat',
        'taxonomy'              => 'page_category',
        'checked_ontop'         => false,
        'echo'                  => true
    );

    wp_terms_checklist( get_the_ID(), $args );

}


function custom_check_meta() {
    add_meta_box( 'custom', 'Test', 'custom_check', 'page', 'normal', 'high', null );
    remove_meta_box( 'page_categorydiv', 'page', 'side' );
}

add_action( 'add_meta_boxes', 'custom_check_meta' );

So I've not currently added any custom functionality to my extended walker (intentional to make sure saving works - this will be modified at a later date).

Now, when I save it sometimes saves the categories correctly, but if I then uncheck a category and resave it doesn't seem to do this. Am I missing something obvious? it also happens if I use the default "Walker_Category".

Edit: I've narrowed this down. It seems that it always expects one thing to be checked, if there's only one and you remove it then it doesn't save. This doesn't happen with the default categories. Would still appreciate any insights as to why this might happen.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far