• Resolved matthewtimothy

    (@matthewtimothy)


    Ive looked at several lines of code for hours and I cant seem to find out why when I do ` $port_args = array( ‘post_type’ => ‘foobar’, ‘posts_per_page’ => -1 );
    $the_query = new WP_Query( $port_args ); ?> and usethe_category()it returns none of the tags assigned to the post. If I do aprint_r()onget_the_terms()I can see the array of assigned categories but I cant figure out how to echo them as plain text. So my question is how can you echo out the categories that are assigned to a post as text (no links) when using WP_Query? It works if I do if (have_posts()):while(have_posts()):the_post;withthe_category()`

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your post is hard to read because you are missing a closing backtick around the first set of code.

    Did you set up the post data with

    while($the_query->have_posts()) :
       $the_query->the_post();

    before you issued the_category()?

    Please show a bit more of the code using WP_Query(), and be sure to enclose it in backticks.

    Thread Starter matthewtimothy

    (@matthewtimothy)

    thanks for replying, I found out what my issue was. I needed to use get_the_terms();.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP_Query display categories assigned to post’ is closed to new replies.