WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Jobs and Locations Listings (6 posts)

  1. rocomu8
    Member
    Posted 1 year ago #

    Hello all, I'm developing a website that has a "Locations" section and a "Jobs" section within it. Each one of these sections needs to have an archive page and a single post page for each Job / Location. The trick is that within each Location, I need to display the Jobs available at that particular location. I wanted to use Custom Post Types for each one, which is fine, but I do not know how to get the Jobs related to a particular Location to display in the Location single page.

    Any help would be greatly appreciated! I've been going round and round with this and no luck.

    Thanks in advance!

  2. David Gard
    Member
    Posted 1 year ago #

    You need to manipulate The Query.

    Can I assume that you have a Custom Post Type called 'jobs' and a Custom Taxonomy call 'location'? If that is the case, you can make a tamplate called 'index-jobs'. This template will be called to show a list of your jobs.

    At the top of the template you need to construct your query.

    /** Build the arguments to get all 'jobs' */
    $args = array(
        'numberposts' => -1,
        'posts_per_page' => get_option('posts_per_page'),
        'paged' => $paged,
        'post_status' => 'publish', // Add private, etc. if you wish
        'post_type' => 'jobs',
    );
    
    /** Check that a Term from the 'location' Taxonomy has been parsed */
    $taxonomy = get_query_var('taxonomy');
    $term = get_query_var('term');
    if($taxonomy === 'location' && $term !== '') :
        $args[$taxonomy] = $term;
    endif;
    
    /** Query the posts */
    query_posts($args);

    Please note that this code is untested, so may require a few tweeks, and may contain the odd typo. However, it should set you on the right path. After this, you can display the results of the query as you so please.

    You could also look in to 'taxonomy.php'. Assuming you are using pretty permalinks, this means that you could display posts using the scructure www.mydomain.com/location/london - this would display all posts that have the term London associated with them (if this is not just your 'jobs' post type, then you can again manipulate the query). When you didplay a list of locations, you link to the 'taxonomy.php' template using get_term_link($term, $taxonomy); - Function Reference.

  3. rocomu8
    Member
    Posted 1 year ago #

    Duck_boy, thank you very much for your suggestions. The issue here is that I need to have a Custom Post type for both Jobs and Locations. Each job and each location will have a detail page with different metaboxes (hours of operations etc...). So how can I associate certain job posts with a specific location? Any ideas?

    Thanks again!

  4. David Gard
    Member
    Posted 1 year ago #

    Ah, with you. I use a plugin called Post2Post by Scribu.

    You create a link in your 'functions.php' file, and then you literally link the posts to each other in the post edit screen. There are then all sorts of new arguments that you can add to your query to code to grab the posts you want.

    Scribu has a page for this plugin that offers tips for beginners and shows code for certain scenarios. He will also come on here and offer support should you hit problems.

  5. rocomu8
    Member
    Posted 1 year ago #

    Duck_boy, thank you very much for your help, this worked like charm!

  6. David Gard
    Member
    Posted 1 year ago #

    No problem.

Topic Closed

This topic has been closed to new replies.

About this Topic