Query posts by page template




















Yes, it is an old answer, for an older version of WP. Very likely the internals have changed. That's a long gap! BenJam BenJam 2 2 silver badges 3 3 bronze badges. Skimmed this page way too quickly, used the accepted answer. This does it. For anyone else, note the array inside the array inside the array Of course the meta query is needed.

The accepted answer is a decade old, for an older version. Doesn't make it incorrect, just outdated for newer versions of WP. I have updated my answer to specify this. So all you need is to use that key in a meta query parameter. Guille Holmann Guille Holmann 11 2 2 bronze badges. This method puts the parameters into an array. The same query as in Example 2 above could be done like this:. As you can see, with this approach, every variable can be put on its own line, for easier reading. It is even possible to use the array style Example 4 to query multiple taxonomies.

Simply supply the taxonomy slug with a string of comma-separated values each value being one term. In the example below, we will get all movie posts starring either Bruce Campbell or Chuck Norris.

You must log in before being able to contribute a note or feedback. As with other examples, place these above your Loop: Example 1 In this example, we concatenate the query before running it. Wordpress query pages with certain template Ask Question. Asked 9 years, 4 months ago. Active 9 years, 4 months ago. Viewed 16k times. Improve this question. Um, how would this work though? What are you trying to achieve? There are a lot of pages on website - continents, with cities childred, which further have accomodation children, or restoraunt children etc.

Each of theese pages have their own page template - so I would like to display all cities with query. Hope this helps? To display the queried posts the code has been added to the original custom template code and the full code is as follows:.

In this final step, we need to create the pagination function that we will use in the custom page template above to display the custom query pagination. To create the pagination function we need to add the following code to the functions. The final step is to call the function we added above in the template so that the pagination is displayed.

To call this function we should use the following code:. Final code that creates a custom page template with this pagination function should be as follows:. If you followed every step the right way you should have the pagination as seen in the image below:.



0コメント

  • 1000 / 1000