displaying-recent-questions php code not working
Hi Rahul,
I used the php code you gave here, http://anspress.io/questions/question/displaying-recent-questions/
added to my theme index.jsp page, but it throws error
Fatal error: Call to a member function have_posts() on a non-object in D:\xampp\htdocs\test\wp-content\plugins\anspress-question-answer\includes\question-loop.php on line 182
i am using latest version of wordpress, theme is from https://roots.io/sage/
could you please let me know what might be wrong? thanks
—– edit —
<?php ap_get_questions(array('showposts' => 5)); ?> <?php if ( ap_have_questions() ) : ?> <div class="ap-questions"> <?php /* Start the Loop */ while ( ap_questions() ) : ap_the_question(); ap_get_template_part('content-list'); endwhile; ?> </div> <?php ap_questions_the_pagination(); ?> <?php else : ap_get_template_part('content-none'); endif; ?>
Hi Rahul, i have added the code, that all my index.jsp file has. maybe their theme is doing something when its hooking up index.jsp?
hmm, it doesnt seem like a theme issue. i used the default wordpress theme twentyfifteen, added that code to index.jsp, and got the same error
Try this:
https://gist.github.com/rahularyan/ecd00606dc54f2134a65
thanks for the code. no error this time. however, it always show No question asked yet!, be the first to ask a question. even when i already posted some questions. it seems like the query doesnt pickup any questions
Updated
hmm, this time no error but no content is displayed. but i checked the markup, div is generated. so i guess something wrong with the while loop so no content get generated.
okay i got it working by doing the following instead of using your while loop. but not sure if thats ideal
foreach ( $questions->posts as $post ) :
echo $post->post_title;
endforeach;
bump
if working then use it 🙂 Cheers.
Show me your code