$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'); ?>customization - Deleted categories still listed until additional page refresh|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)

customization - Deleted categories still listed until additional page refresh

matteradmin12PV0评论

I've tried using wp_delete_category() and wp_delete_term() to delete a category, but after the page reloads, the deleted category still shows up in the results of get_categories(). But if I reload the page a second time, the category is gone.

How can I make sure it goes away after the first reload?


I'm grabbing form data with a $_POST and handing to wp_delete_category(). This is all taking place on a plugin settings page. Here's a little snippet of my code. Suggestions welcome.

if ( isset($_POST['deleteSelectedCategories']) ){

    $cats = $_POST['catsToDelete'];
    $catsArray = explode(',', $cats);

    foreach ($catsArray as $catID) {
        // wp_delete_category( $catID );        
        wp_delete_term( $catID, 'category' );
    }
}

I've tried using wp_delete_category() and wp_delete_term() to delete a category, but after the page reloads, the deleted category still shows up in the results of get_categories(). But if I reload the page a second time, the category is gone.

How can I make sure it goes away after the first reload?


I'm grabbing form data with a $_POST and handing to wp_delete_category(). This is all taking place on a plugin settings page. Here's a little snippet of my code. Suggestions welcome.

if ( isset($_POST['deleteSelectedCategories']) ){

    $cats = $_POST['catsToDelete'];
    $catsArray = explode(',', $cats);

    foreach ($catsArray as $catID) {
        // wp_delete_category( $catID );        
        wp_delete_term( $catID, 'category' );
    }
}
Share Improve this question edited Feb 26, 2019 at 15:11 thingEvery asked Feb 26, 2019 at 6:22 thingEverythingEvery 1471 silver badge9 bronze badges 4
  • Do you have any caching plugins active on that site? Does your hosting use any caches? – Krzysiek Dróżdż Commented Feb 26, 2019 at 6:36
  • No caching plugins installed and nothing in the cpanel. Any other changes I make show up right away. Basically, no evidence of caching as far as I can tell. – thingEvery Commented Feb 26, 2019 at 6:59
  • When exactly are you running wp_delete_category()? In what context? – Jacob Peattie Commented Feb 26, 2019 at 10:05
  • @JacobPeattie I'm calling it from a plugin settings page. I've updated my question. – thingEvery Commented Feb 26, 2019 at 15:13
Add a comment  | 

1 Answer 1

Reset to default 0

I've found a workaround by forcing the second refresh, but I'm sure there's probably a better way to do this.

In order to make the process smoother for the user, I'm thinking I'll have to do an AJAX post and then refresh on success to show the updated data.


if ( isset($_POST['deleteSelectedCategories']) ){

    $cats = $_POST['catsToDelete'];
    $catsArray = explode(',', $cats);

    $success = 0;

    foreach ($catsArray as $catID) {
        if ( wp_delete_term( $catID, 'category' ) ) {
            $success++;
        }
    }

    if ($success > 0) {
        echo '[Here I have some HTML to block out the screen 
            and show a message to the user, 
            and then the following meta refresh:] 
            <meta http-equiv="refresh" content="0" />';
    }
}
Post a comment

comment list (0)

  1. No comments so far