• Hello,

    I’ve tried searching high and low for this but haven’t been so lucky. I’m trying to do a search for a custom post in a custom taxonomy.

    This gets me all the posts in a custom taxonomy.
    query_posts( array(‘directory’ => $termslug) );

    however, I need to apply a search term (query_String) to this as well.

    Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Need more info. What is in the query_string?

    Thread Starter Harv27

    (@harv27)

    I’m using this on a custom search results page.

    query_String contains the search keyword (s=blah) and another parameter – post_type.

    If what you want to do is search the titles and contents for ‘blah’ in posts of post_type, you should be able to do that with a filter.

    If that is the case, please provide an example of the query_String and I will try to set up the code.

    Thread Starter Harv27

    (@harv27)

    I’m trying to search the titles of a specific post type (vendors) within custom taxonomy (directory).

    here is the query_string
    s=apple&post_type=vendors

    Thread Starter Harv27

    (@harv27)

    I should also mention that I’ve modified my search.php to refer to another page based on post type.

    I think this is what you want. I have assumed that the query string variable is $query_String and that what you see in your sample above is literally correct. This is obviously incomplete, so you will need to adapt it to your other code for the theme.

    function mam_posts_where ($where) {
          global $mam_global_where;
          if ($mam_global_where) $where .= " $mam_global_where";
          return $where;
       }
       if (preg_match('/^s=([^&]+)\&post_type=(.+)$/',$query_String,$matches)) {
          $mam_global_where = " AND $wpdb->posts.post_title LIKE '%$matches[1]%'";
          $args = array(
             'post_type' => $matches[2],
             );
          global $wp_query;
          $query_posts($wp_query->query, $args);
          $mam_global_where = '';  // Turn off filter
          // Process posts here
       } else {
          // Bad query string
       }
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘search in custom taxonomy’ is closed to new replies.