How to – add condition to search only for posts in specific category(ies)
-
Add condition to search only for posts in specific category(ies) within this function?
function post_exist($title) { global $wpdb; $post_slug = stripslashes(sanitize_post_field('post_name', $title, 0, 'db')); $query = "SELECT ID FROM $wpdb->posts WHERE 1=1 AND post_status = 'publish' AND post_type = 'post'"; $args = array(); if (!empty ($title)) { $query .= ' AND post_name = %s'; $args[] = $post_slug; } if (!empty ($args)) return $wpdb->get_var($wpdb->prepare($query, $args)); return 0; }
Does this function too bad for CPU performance?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to – add condition to search only for posts in specific category(ies)’ is closed to new replies.