I am using the Pages with category and tag plugin to assign tags and categories to pages. And now I would like to retrieve a list of items with specific tags associated with a page and can’t seem to get it to work.
The code I am using is as follows; kludged together from what I can find online for fetching posts based on tags like this StackOverflow post. And please excuse the very much “development” roughness in place in this stuff for now:
<?php
$tags = get_the_tags();
print_r($tags);
$args = array(
"numberposts" => 3,
"post_type" => "page",
"tax_query" => array(
array(
"taxonomy" => "page_tag",
"field" => "term_id",
"terms" => $tags
)
)
);
$pages = get_pages( $args );
print_r($pages);
?>
WP_Query
instead ofget_pages()
orget_posts()
. The parameters are documented with lots of examples in WP Developer Resources: developer.wordpress.org/reference/classes/wp_query