WordPress.org

Forums

WP Job Manager
[resolved] Include categories in keyword search (4 posts)

  1. kevinhisko
    Member
    Posted 1 year ago #

    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/

  2. Mike Jolley
    Member
    Plugin Author

    Posted 1 year ago #

    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

  3. kevinhisko
    Member
    Posted 1 year ago #

    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'

  4. Mike Jolley
    Member
    Plugin Author

    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Job Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic