Display CPT Archive By category

I have archive-cpt.php working fine to display all categories of CPTs. Now I want to display the CPT by individual category, but it isn't working. http://hro.minationalguard.com/jobs is my archive for all categories. The menu there doesn't work for individual categories. I also tried /jobs/cat-slug, and that gave me a 404.

  • Vinod Dalvi
    • WP Unicorn

    Hi Josh,

    I hope you are well today and thank you for your question.

    Do you mean the following default category pages don't work on your site?

    http://hro.minationalguard.com/category/technicianarmy/
    http://hro.minationalguard.com/category/technicianarmy/

    If yes then would you mind if I logged in to your site and did some testing? This might help get to the bottom of this faster. If this is ok, just grant me temporary admin access to your site by clicking "Grant Access" button in the WPMU DEV Dashboard Settings as described on the following page and reply on this thread after granting it?

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Please advise.

    Kind Regards,
    Vinod Dalvi

  • Michael Bissett
    • Recruit

    Hey @Josh, reaching out here from the live chat earlier today. :slight_smile:

    I'd like to have a deeper look at what's going on here, could you please send in the following:

    - Mark to my attention, the subject line should contain only: ATTN: Michael Bissett
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include WordPress admin access details
    - Include FTP log-in details
    - Include any relevant URLs for your site

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thanks a bunch! :slight_smile:

    Kind Regards,
    Michael

  • Michael Bissett
    • Recruit

    Hey @Josh, thanks for your patience here! :slight_smile:

    After digging into this further, the problem actually wasn't related to the template... but rather, it was due to the configuration of the custom post type.

    It was assigned the default WordPress Category taxonomy, which led WordPress to try treating the categories created for that post type as if they were containing normal WordPress posts. However, as they didn't contain normal posts, and since there were no normal WordPress posts made on your site, any time the categories were viewed, the posts feed would show up blank.

    Inside of CPT UI (the plugin you're using to manage these custom post types), I created a custom taxonomy called "jobs_categories", and assigned it to your custom post type (I also set it as a built-in taxonomy inside of the post type itself).

    After creating a category inside that custom taxonomy, and assigning one of your existing job listings to that category I created, I am now seeing that it shows up there. :slight_smile:

    At this point, you'll need to create new categories inside of that custom taxonomy I created, and migrate your posts over to those categories (removing them from the default categories they were assigned to previously).

    Afterwards, you'll need to remove the "Categories" entry as a built-in taxonomy from your custom post type, so that job listings created in the future won't end up in the default WordPress category system.

    Hope this helps! :slight_smile:

    Kind Regards,
    Michael

  • Josh
    • Site Builder, Child of Zeus

    Simply magic. I'm glad I asked because it would have been a lot more blogs to read before I came to that conclusion. Now I just need to copy/paste my archive file to display them how I want. Nothing I haven't done already... Thanks for your help and patience!

  • Josh
    • Site Builder, Child of Zeus

    @Michael Bissett: What does my category archive file need to be named in this case? I will likely just create one file with if/then conditions for each category. Nothing I am using seems to work right.

  • Sumit Kumar
    • Site Builder, Child of Zeus

    Hi @Josh,

    As michael created a custom taxonomy with the name "jobs_categories", so then your php file will be "taxonomy-jobs_categories.php".

    For further queries on how to name a wordpress php file, please find this hierarchy chart: http://codex.wordpress.org/images/9/96/wp-template-hierarchy.jpg

    Let us know, if we can further assist you in anything, there
    Have a nice weekend :slight_smile:

    Warm Regards,
    Sumit

  • Josh
    • Site Builder, Child of Zeus

    Thanks much! So close to being done with this project...I need to echo the taxonomy name at the top of the category archives. I was trying to do a series of else if conditions, but thought there was probably a more direct approach. Being that it's a custom taxonomy, I couldn't find much in the codex...Any suggestions?

  • Josh
    • Site Builder, Child of Zeus

    Aha! Please disregard last request. If any other user is trying to echo a custom taxonomy, use this:

    <?php
    $terms = get_the_terms( $post->ID , 'custom_taxonomy_name' );
    foreach ( $terms as $term ) {
     echo $term->name;
    }?>

    Thanks for your help, everyone!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.