Support » Plugin: WP Job Manager » Include categories in keyword search

  • Resolved kevinhisko

    (@kevinhisko)


    I am trying to include the categories with the search keyword query. I have been modifying the wp-job-manager-functions.php page and have had no luck, see below.

    $post_ids = array_merge( $post_ids, $wpdb->get_col( $wpdb->prepare( “
    SELECT ID FROM {$wpdb->posts}
    LEFT JOIN $wpdb->term_relationships ON (ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    OR $wpdb->term_taxonomy.taxonomy = ‘%%%s%%’
    WHERE post_title LIKE ‘%%%s%%’
    OR post_content LIKE ‘%%%s%%’
    AND post_type = ‘job_listing’
    AND post_status = ‘publish’
    “, $args[‘search_keywords’], $args[‘search_keywords’] ) ) );

    https://wordpress.org/plugins/wp-job-manager/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mike Jolley

    (@mikejolley)

    OR $wpdb->term_taxonomy.taxonomy = '%%%s%%'

    Thats the name of the taxonomy, in this case job_listing_category. You need to instead check the keyword against the term’s name. This requires an additional join.

    http://codex.wordpress.org/Database_Description#Table:_wp_terms

    Thanks! Is there something I need to update in the job-filters.php file too. I have tried the suggestion although am having no luck.

    SELECT ID FROM {$wpdb->posts}
    LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
    WHERE post_title LIKE ‘%%%s%%’
    OR $wpdb->terms.slug LIKE ‘%%%s%%’
    OR post_content LIKE ‘%%%s%%’
    AND post_type = ‘job_listing’
    AND post_status = ‘publish’

    Plugin Author Mike Jolley

    (@mikejolley)

    Use $wpdb->terms.name.

    Also important, your query will exclude any job without a category.

    Finally, probably test this by hardcoding in the strings to the query so you can test if its working or no, and enable WP_DEBUG in case there is an error in your SQL.

    http://codex.wordpress.org/WP_DEBUG

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Include categories in keyword search’ is closed to new replies.