php - Wordpress show result posts from query

280

I am pretty new in Wordpress and I want to call a template to show the result posts from my query, which i have written in theme's functions.php:

$quotes = get_posts(array('post_type'=>'post', 'orderby'=>'title', 'order'=>'ASC', 'meta_value' =>$criterion)); 

I have the result and the template page but I don't know how to send them to the specific-template. How can I call template and send $quotes, for e.g. call_template(template_name, $quotes)

102

Answer

Solution:

Should just be a case of putting it in a function, returning $quotes, making sure that functions.php is included (if it isn't already) and then calling the function?

Unless you were planning to hook it into another wordpress function.

156

Answer

Solution:

if you are simply trying to show it on some page, than just make page template and query onto that page, and place a wordpress have_posts() loop, you should refer to template herirachy https://developer.wordpress.org/themes/basics/template-hierarchy/

and you will know which php file from the theme directory the given page is loading from. or else there is an interesting plugin to know which template files are involved on a given page, this plugin https://developer.wordpress.org/themes/basics/template-hierarchy/

People are also looking for solutions to the problem: php - Move file by rename()

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.