In Wordpress, I am working on a theme for a custom post type (books) in which I am calling a list of authors that come from another custom post type (people). They are linked through the wordpress plugin Posts 2 Posts.
My Aim is to create a sequence of authors separated by comma, like this: Author1, Author2, Author3, Author4.
With the code below, the result is a sequence of authors like this : Author1Author2Author3Author4. The same code also works to get a list of elements by adding a li division below the_post();, with this results :
-Author1
-Author2
-Author3
-Author4
The piece of code :
if ($autores->have_posts()):
echo '<li>';
echo '<b>Autores: </b>';
while ( $autores->have_posts() ) : $autores->the_post();
echo '<a href="';
echo the_permalink();
echo '">';
echo the_title();
echo '</a>';
endwhile;
echo '</li>';
endif;
Maybe this question can be answered in multiple forms. One is by converting this object into an array of elements (I don't know how...yet?). At least, I found a very useful method which works with taxonomy elements (here: https://wordpress.stackexchange.com/a/238362), but this is not working in my case, maybe because I have one object, so when I make a count($autores) I always have 1 as result. I also wonder if it is possible to use css to convert a list of elements into inline elements and separate them with commas.
I will really appreciate if someone here can give me an idea to resolve this question. Keep searching by my side...
the_permalink
echo's internally, it doesn't return a title, soecho the_permalink();
is the same asecho ""; the_permalink();
. the same is true of any WP function starting withthe_