0

How can I fit this category slug

<?php $term = get_queried_object(); echo $term->slug; ?>

into this page content <?php $page = get_posts([ 'name' => 'slug-goes-here', 'post_type' => 'page' ]); if ( $page ){ echo $page[0]->post_content;} ?>

2
  • 1
    What do you mean by "fit"? Also, Pages (post type page) by default do not have categories, so did you manually add the category taxonomy to the page post type? And by "category", are you referring to the default category taxonomy?
    – Sally CJ
    Commented Dec 8, 2021 at 16:46
  • I'm using a category slug that has the same slug as a corresponding page. So when someone visits the post category archive I can display the contents of the page on the archive page.
    – Pete
    Commented Dec 9, 2021 at 0:44

1 Answer 1

0

Worked it out...

<?php $term = get_queried_object(); ?>
<?php   
$page = get_posts([
    'name'      => $term->slug,
    'post_type' => 'page'
]);
if ( $page ){ echo $page[0]->post_content; }    
?>  

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.