• Resolved Simalam

    (@simalam)


    I’m trying to combine multiple post types on an archive page, however when I do so i get a bunch of errors all over the page. The actual archive listing works properly, it just seems to break everything else outside of the main query.

    Error displayed on site, multiple times/places:

    Warning: Illegal offset type in isset or empty in /home/.../wp-includes/post.php on line 1039

    That line of code is:

    if ( empty($wp_post_types[$post_type]) )

    Code being used:

    function archive_filter($query) {
      	if ( !is_admin() && $query->is_main_query() && $query->is_archive) {
      		if ($query->query_vars['post_type']=="jobpost" || $query->query_vars['post_type']=="hotjob"){
        			$query->query_vars['post_type']=array( 'hotjob','jobpost');
      		}
    	}
    }

    All post types have publicly_queryable and has_archive to true.

    I’ve used the information on the codex page and even tried in a fresh install of both wordpress and theme.

Viewing 1 replies (of 1 total)
  • Thread Starter Simalam

    (@simalam)

    Ok, I found the problem and fixed it. Turns out the problem was the fact I was modifing an archive query, instead of a non-archive query.
    It was sending an array to line 1039 of post.php, instead of a string, for the non-main query.

    I added the following line into the code:

    $query->is_post_type_archive = false;

    above this line:

    $query->query_vars['post_type']=array( 'hotjob','jobpost');

    Would be nice if the issue with modifying the archive query was mentioned in the codex for custom post types.

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with multiple Custom Post Types on Archive Page Query’ is closed to new replies.