I have set up a function to dynamically create pages through query variables. The use case is that we're calling a job's board API and then generating the URL and content of the page based on what get's returned.

Here is the code doing that work:

add_action( 'init', 'career_page_rewrite' );
function career_page_rewrite() {

    add_filter( 'query_vars', function ( $query_vars ) {
        $query_vars[] = 'dept';
        $query_vars[] = 'role';

        return $query_vars;
    } );

    add_action( 'template_include', function ( $template ) {
        if ( ! get_query_var( 'dept' ) || get_query_var( 'dept' ) === '' ):
            return $template;
        if ( ! get_query_var( 'role' ) || get_query_var( 'role' ) === '' ):
            return $template;

        return get_template_directory() . '/career-listing.php';
    } );

The good news is that this works well and the pages are being generated correctly with all of the correct information.

The problem is that the SEO information is wrong and I'm not quite sure where to start in getting it to work correctly. The SEO and Opengraph information it's pulling is from one of our blog posts.

So, for example, the job page might be for "Construction Worker" but the SEO metadata information being pulled might be for the blog post "How to use an umbrella".


Why is that the post being pulled in? I don't understand why a single post vs. an archive page gets pulled in. When I get_page_template($post->ID) it returns as page.php. But when I use global $template I get career-listing.php. I don't understand the disconnect and when the site is including the correct template. Because it is.


Your Answer

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

Browse other questions tagged or ask your own question.