Create a post automatically if search result has zero results

Assuming you are using the standard WordPress search, you can get the searched number with get_search_query So this code will create a new draft post if no results were found for the search: $match = get_page_by_title( sanitize_title( get_search_query() ), OBJECT, [‘post_type’ => ‘post’] ); if ( empty( $match ) ) { wp_insert_post( [‘post_title’ => sanitize_title( … Read more

Help with query_posts function

The query_posts() function is almost wholly unnecessary and is discouraged in favor of WP_Query(). That being said we can look at the WP_Query() docs as they’re almost the same. The cat parameter accepts either a comma separated string or integer. In this case we can use: query_posts( array( ‘cat’ => 1, ‘posts_per_page’ => ‘8’, ‘post__not_in’ … Read more