How to iterate through custom posts and add the title to an array
I see two problems with the code you’ve written. The first one is that the_title() echos the post title although returning the title would be more appropriate in this context. Also wp_reset_postdata() should be after the while loop inside the if statement. But as you mentioned that you only need the post titles, you can … Read more