get_the_title() doesn't work in custom post type loop
-
I would like to display list of custom posts after single post. Is only one requirement: custom posts to display must have minimum one tag same as the single post title.
First, I have the loop – it’s working.
Rather then this code:<?php $tag_slug = str_replace( ' ', '-', get_the_title() ); $args = array( 'post_type' => 'ksiazka', 'tax_query' => array( array( 'taxonomy' => 'tag_ksiazka', 'field' => 'slug', 'terms' => $tag_slug ) ), 'post_status' => 'publish', 'order'=> 'ASC', 'orderby' => 'title' ); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); ?> <!-- post id, title, thumb, etc --> <?php endforeach; wp_reset_postdata(); ?>
Everything is working properly when in place of ‘get_the_title()’ is real tag – posts list is correct.
Why ‘get_the_title()’ doesn’t working in this case?
Thanks for your help.
- The topic ‘get_the_title() doesn't work in custom post type loop’ is closed to new replies.