How to filter by category name in custom post types?

Looking at the official wordpress documetation for WP_Query category https://developer.wordpress.org/reference/classes/wp_query/#category-parameters It should be something like $args = array( ‘post_type’ => ‘fruits’, ‘posts_per_page’ => 4, ‘category_name’ => ‘apple’ // category_name instead of category ); $query = new WP_Query( $args ); This is assuming you actually use the category and not custom taxonomy Also if actually refer … Read more

i want to auto create pages with shortcode when plugin is activated and delete when deactivated

The problem is a basic PHP problem rather than a WordPress problem. wp_insert_post is expecting ‘post_content’ but you’ve given it ‘$post_content’ and it needs a string as it’s value aka “[gd_shortcode]” not [gd_shortcode]. The same is true of your post status, it has a $ in it that should not be there. See the examples … Read more