0

So, I deleted multiple post of type page (sent them to trash, went to trash and permanently deleted them), but one of my functions didn't work like it was supposed to so I went and investigated, it was because the post_exists( $slug , '', '', 'page') returned a truthy value.

For example just to test it, for

require_once( ABSPATH . 'wp-admin/includes/post.php' );
echo post_exists( 'home', '', '', 'page');

it echoed 363, so I went to the database to check and found that not only is it not deleted per se, but it appears as published:

mysql> SELECT ID, post_name, post_title, post_status, post_type FROM wordpress.wp_posts WHERE ID=3
63;
+-----+-----------+------------+-------------+-----------+
| ID  | post_name | post_title | post_status | post_type |
+-----+-----------+------------+-------------+-----------+
| 363 | home      | Home       | published   | page      |
+-----+-----------+------------+-------------+-----------+
1 row in set (0.00 sec)

I know I'm probably overlooking a fundamental and basic thing about how wordpress works, but I didn't find anything useful while searching for this.

So, how can I delete posts definitively without actually going to the database and deleting it?

6
  • The record should not be in the database after you emptied the trash. Either you're somehow looking at different posts, or you have a hook in your theme or a plugin that is interfering with standard WP behaviour.
    – vancoder
    Commented Jan 27, 2022 at 22:19
  • I'm not looking at different posts, because I specifically looked them up by id in the database. I could have a hook that interferes, but I have no idea what could it be, as I didn't really do anything out of the ordinary that I can think of. The other thing is, that programatically added posts don't show up at all on the admin page. Commented Jan 27, 2022 at 22:37
  • Did you deleted or sent them to trash manually from admin panel, or programmatically, using your own functions? The second is more convenient, because it sounds like. So, show us your secret code.
    – Max Yudin
    Commented Jan 27, 2022 at 23:00
  • No, I deleted them on the admin panel. I wanted to add them programatically and this didn't work at first because the condition in this returned false, meaning the post_exist evaluated to truthy and that's how I found that the posts still exist. if ( ! post_exists( $slug, '', '', 'page') ) { $postarr = array( 'post_name' => $slug, ... ); wp_insert_post( $postarr ); } Commented Jan 27, 2022 at 23:08
  • After stashing all changes is still get the following warnings when trying to visit the deleted pages: Notice: Trying to get property 'public' of non-object in /var/www/html/wp-includes/class-wp.php on line 242 Notice: Trying to get property 'protected' of non-object in /var/www/html/wp-includes/class-wp.php on line 242 Notice: Trying to get property 'private' of non-object in /var/www/html/wp-includes/class-wp.php on line 243 Notice: Trying to get property 'exclude_from_search' of non-object in /var/www/html/wp-includes/class-wp.php on line 243 Commented Jan 27, 2022 at 23:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.