I am trying to get all the posts associated with the Title of a page.
This is what I currently have:
<?php
$title_to_tag_posts_query = new WP_Query( array(
'tag' => get_queried_object()->post_name
) );
while ( $title_to_tag_posts_query->have_posts() ) : $title_to_tag_posts_query->the_post(); ?>
<p>
<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php the_date(); ?>
</p>
<?php endwhile; ?>
It works in pulling all the posts where the tag matches the title of the Page. Except, it doesn't work with posts under a custom post type, even though they are tagged. So I almost have it, but not quite. I'm still missing content from the CPT posts.
I've been playing around with it by using some conditionals but all I seem to do is break it. The CPT I am trying to get the posts from has the capability_type
of 'post' so I'm pretty sure that's not the problem. I think I just may be missing the proper conditional or appropriate way to query for this?
'post_type'
arg or set it to'any'
, eg'post_type' => 'any'
.