On my blog, I wrote several posts about wp_query classes and how to use them to create multiple queries and multiple loops. I am a big fan of wp_query and often create advanced and custom queries on client sites and my site. But if it goes too far, there will be shortcomings. A reader correctly commented in my recent post that I could more efficiently create the technique I demonstrated by using loops to specify different styles for the first post. Therefore, in this post, we will use wp_query to create multiple loops, but we will show you the most effective method. That is, it runs only one query to create multiple loops. The
The advantage of this is that the database can only be used once. You can then run the loop as needed using all the data imported by wp_query. Let’s see how it works. What we need to do is that this post will create a section at the top of the \
If necessary, you can imitate the post. The first thing to do in the development and installation of WordPress code editor query settings is to run the query. Upload this post to the front page of the home page. Put it in the theme template file in PHP. However, you can place them anywhere in the topic where you want to run multiple rings. Note: if you are using a third-party theme, put all content in a sub theme instead of a third-party theme. If you do not know how to set up a subtopic, refer to the guide. My query is as follows: Load summary 93772b5f9a86936aebe4d03b530c3d89 this query will get posts of three post types. Posts, pages, and my custom post type books. The
Now that you have imported posts from the database, you must start setting up the code to output. After the output setting query, add the following in braces: Load the summary 93772b5f9a86936aebe4d03b530c3d89, which will generate the section element containing all our posts. A variable named $count is also defined and set to 0. Upload one per loop The first loop within the first loop runs to output my custom post type. Therefore, it contains a condition tag to check the post type within the ring. In addition, to ensure that the $count value is 0 and stop the loop running again after running, increase the value by 1. The
The codes are as follows: Load the summary 93772b5f9a86936aebe4d03b530c3d89, which contains the get\u post\u type() function that identifies the post type. The loop is executed only when get\u post\u type() book and the count value is 0. Finally, $count++ increases the value of the $count variable as follows: 1. the last element of this loop is rewind_posts(). You will find that the loop does not run correctly because it skips posts of other post types posted after this book post. The
Running the second loop is now the second loop. First and
If it is loaded quickly, the user experience and search engine ranking will be improved. What don’t you like? As posts, categories, and custom post types, make sure you can try the technology and do something today. The
How do I use this technology on your site? Tell us in the comments! Tags: CSS custom PHP