Query posts in archive.php
-
I am trying to run an extra query within the archive.php. But everytime time it executes, it returns the same results which are not the results that I am after.
Below is a copy of my code that I am running in the archive file, which is located before the if (have_posts()) : while (have_posts()) : the_post(); code.
The code should get the slug of the tag that I am viewing, and use that to check if there is another post in a different post type with the same slug.
$tag = get_queried_object(); $tag_title = $tag->name; // Same as single_tag_title() $tag_slug = $tag->slug; $tag_id = $tag->term_id; $CheckForPost = array( 'post_type' => 'player-profiles', 'post_status' => 'publish', 'posts_per_page' => 1, 'post_slug' => '$tag_slug' ); $GetProfileCheck = null; $GetProfileCheck = new WP_Query($CheckForPost); if (have_posts()){ // return true }else{ // return false }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Query posts in archive.php’ is closed to new replies.