wp_trash_post() duplicates post to trash

As the function name suggests, wp_trash_post() only trashes a post. If you want to have a post completely deleted then you can use wp_delete_post( int $postid, bool $force_delete = false ) instead. https://developer.wordpress.org/reference/functions/wp_delete_post/ When the post and page is permanently deleted, everything that is tied to it is deleted also. This includes comments, post meta … Read more

Tag for custom post type

Use taxonomies parameter when registering custom post type: register_post_type( ‘car’, [ ‘labels’ => [ /* … */ ], ‘public’ => true, ‘taxonomies’ => [ ‘post_tag’, ‘categorycar’ ], ] ); Or, after registering post types, use register_taxonomy_for_object_type() function. register_post_type( ‘animal’, /* … */ ); register_post_type( ‘science’, /* … */ ); register_taxonomy_for_object_type( ‘post_tag’, ‘animal’ ); register_taxonomy_for_object_type( ‘post_tag’, … Read more

How can get the last post date of the user?

In your sample code the $latest_posts is an instance of WP_Query class. If you want to get the latest post’s date, you should do this: $latest_posts = new WP_Query( $args ); $last_date=””; if ( $latest_posts->have_posts() ) { $latest_posts->the_post(); $last_date = get_the_date(); } return $last_date;