I need to list all posts associated to a custom post type "jobs" with support for pagination and Yoast SEO metas (canonical URL, next\prev links, "noindex,follow" subpages). You may consider reading https://github.com/Yoast/wordpress-seo/issues/7673#issue-249879395 that explains Yoast SEO doesn't handle correctly the metas on custom templates that use a custom WP_Query().

Option 1: Custom Page Template

I create a custom page template with this code:

# Template Name: Jobs List 

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' => 15, 'paged' => $paged, 'post_type' => 'jobs', 'orderby' => 'title', 'order' => 'asc' );
$wp_query = new WP_Query($args);

<?php get_header(); ?>

<?php if ($wp_query->have_posts()) : ?>

    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

        <?php get_template_part( 'template-parts/content', 'jobs-list-item' ); ?>

    <?php endwhile; ?>

    <?php print_pagination($wp_query); ?>

<?php else: ?>

<?php get_template_part( 'template-parts/content', 'nothing-found' ); ?>

<?php endif; ?>

<?php wp_reset_postdata(); ?>

<?php get_footer(); ?>

The above code lists all posts in the "jobs" custom post type, with support for pagination. It works fine, but Yoast SEO metas (canonical URL, next\prev links and the custom robots "noindex,follow") are not working. If I use the workaround described in the https://github.com/Yoast/wordpress-seo/issues/7673#issue-249879395 then it works fine.

So I was thinking to use another trick to "natively" support Yoast SEO:

Option 2: "All Jobs" Category

I create a category "All Jobs" for the custom taxonomy "Jobs Category" and I assign all "jobs" posts to that category too (as secondary category). So then to list all posts in the "jobs" custom post type I can simply use the taxonomy template taxonomy-jobs-category.php, the permalink would be like website.tld/jobs-category/all-jobs/ and it would support perfectly both pagination and Yoast SEO metas, because it follows the "default Wordpress flow".


What do you think about Option 2? Do you have any recommendations?

  • I don't see any bad issues with your option 2. It is really better than custom page template, because natively to wordress Aug 23, 2017 at 10:37
  • Why do you need a category at all? Just create a template for the post type archive. See the template hierarchy. Custom post types will already have an 'all' view. Aug 23, 2017 at 11:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.