4 ms·
What about generating queries is complex enough to make you feel like such a simple generator is necessary? I would heartily agree that the documentation [1] i
by jwarren 13y ago
What about generating queries is complex enough to make you feel like such a simple generator is necessary?
I would heartily agree that the documentation [1] isn't great, but it's generally very easy to use and quite powerful.
[1] http://codex.wordpress.org/Class_Reference/WP_Query http://codex.wordpress.org/Class_Reference/WP_Query
- d23 13y ago> To begin with, have_posts(), which calls $wp_query->have_posts(), is called to see if there are any posts to show. If there are, a while loop is begun, using have_posts() as the condition. This will iterate around as long as there are posts to show. In each iteration, the_post(), which calls $wp_query->the_post() is called, setting up internal variables within $wp_query and the global $post variable (which the Template Tags rely on), as above. Seriously, you're apologizing for this? This is just one of the myriad examples of what a mess Wordpress is, and it's at core of the functionality.
- jwarren 13y agoSorry, maybe I wasn't clear enough there. I feel that the way you construct an array and pass it to WP_Query is clear and easy to use. Here's a random example from that docs page: $args = array( 'post_type' => 'my_custom_post_type', 'meta_key' => 'age', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'age', 'value' => array(3, 4), 'compare' => 'IN', ) ) ); $query = new WP_Query($args); So it's returning posts that: - Are of the post type: "my_custom_post_type", - That contain a custom field with the key of "age", - That are in ascending order by the value of the aforementioned custom field, - Where the "age" field is equal to either 3 or 4. That seems relatively easy and straightforward to me. The bit that you brought up is the loop, which is the canonical way of displaying the posts retrieved by a query. You don't have to, of course, you can just get an array of them and foreach your way through. The abstraction does allow for quick, easy, and relatively flexible development. I'd fully believe that it's messy on the backend, but that honestly doesn't normally affect my day-to-day usage. Now, I'm not about to argue the merits of the core architecture of Wordpress - that's beyond my expertise. But I use it daily for client work, and it works very well for my needs.