Check the database for a postmeta field

You don’t need to set a new WP_Query since you are looping through the data of the octopus. I would do the following in your case: Create a function that checks if there is a post with an octopus_id given function post_with_octopus_id_exists( $octopus_id ){ //If for some reason the $octopus_id given is empty return false … Read more

Make categories appear random

You could hook into the pre_get_posts action hook and set the posts’ order to random only for specific categories. Here’s a basic example on how to achieve so: function sort_posts_randomly( $query ) { if ( ! is_admin() && $query->is_main_query() ) { if ( is_category( ‘category id, slug, or name’ ) ) { // Sort the … Read more

How to search through “post title” and “tags” using WP_Query?

Try getting rid of the “0” key in your tax_query and meta_query array. $query_args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘order’ => ‘ASC’, ‘orderby’ => ‘none’, ‘posts_per_page’ => ‘100’, ‘offset’ => ‘2’, ‘page’ => ‘2’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘name’, ‘terms’ => array(‘test’), ‘operator’ => ‘IN’, ), ‘relation’ … Read more

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