11 ms·
Show HN: The WordPress Query Generator, create WP loops in plain English
- st3redstripe 13y agoFont is huge!
- gnaritas 13y agoAs it should be for this kind of thing.
- woah 13y agoIt's unfortunate that this is necessary. Other frameworks have normal iterators, the for loop, maybe a while loop as well. They just show items from the db. Simple. WP has somehow fetishized this simple affair into "The Loop"- 3 different functions, all with slightly different behavior and syntax, with about 40 arbitrary defaults each that must be overridden if you want basic, bare bones behavior. It's no surprise that WP is the only framework that needs an online generator for something that is usually so simple. I could get into "The Post" as well, but I'll leave that for another time.
- jblz 13y agoYou can easily loop through the results of this call with for or while: http://codex.wordpress.org/Class_Reference/WP_Query http://codex.wordpress.org/Class_Reference/WP_Query
- jwarren 13y agoWhat 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.
- meritt 13y agoWhile I agree that WP is an absolute mess, I want to remind you that this has been how WP has operated for long before the vast majority of today's frameworks have existed. WP isn't a framework. It's a CMS. A shitty one that needs to go away, but criticizing it for not having the same feature-set as modern frameworks is simply unfair and unnecessary.
- voyou 13y agoWhile WordPress is a bit of a shitty CMS, all the other CMSes I've tried are even worse. Are there any actually good alternatives?
- rslonik 13y agoI'm with you. Saying WP is a shitty CMS is easy, but where is a good alternative? There is none. Anyone can say anything about WordPress, but the FACT is that it's most used CMS, with a BIG community and market arround it.
- blindhippo 13y agoWordpress is a code architectural mess, but as a CMS it's one of the best I've ever seen. (CMS's are deceptively complicated to build) People saying it's shitty don't know what they are talking about (even you point out others you've tried are worse). Wordpress is best in class for what it is: open source content manager. It's best use case is for a simple blog. It can be bashed into submission to be an ok general CMS or even a community managment solution. Past that though, it's architecture falls to pieces - but then, you wouldn't use a hammer to drill a hole would you?
- coolsunglasses 13y agoThe real difficulty in CMSs isn't in making the CMS, it's making a CMS that is reasonably extensible and configurable by end-users as well as coders. Too far into that extreme gets into Drupal-land.
- juddlyon 13y ago
- wyck 13y agoThere is no "fetish" for The Loop, it's just a basic function, hardly something you can bash WordPress about. It does not "need" an online generator and I don't know any actual developer who would use one. This seems geared towards beginners since WordPress has a low barrier of entry and there is nothing wrong with that. I have `WP Query` as a snippet on my IDE because it's faster than typing, this is essentially the same as a web interface , it makes no sense to bash what is essentially auto-complete. WordPress comes with many default parameters because it's convenient, if you don't want to use them, create your own, there's nothing stopping you from doing that. tl;dr The last time I checked a `while loop` was a basic control statement of most every programming language.
- ChrisClark 13y agoOn Chrome I can't delete 'anyone', 'all' or 'any' from the text fields. I can only type new characters in front of the default text. On the initial load, 'anyone' is also cut off, looks like 'anyor'. Other than that, this looks like a very nice site for a non-programmer or new programmer who wants to customize a theme they found.
- irunbackwards 13y agoHey ChrisClark, these are placeholders, so you can type and they will clear out. We'll take this into consideration and maybe change the text color so it's a little more apparent. Dually noted about the cut off "anyone" -- thanks for the feedback!
- irunbackwards 13y agoJust fixed the placeholder issue! Curious -- what operating system are you on? I'm using the latest version of Chrome on Windows 7 and can't reproduce the "anyone" issue, I'll check it out on my Mac in just a few.
- Jake232 13y agoGreat, however I can't help but think that 10minutes spent making the response AJAX would make the app much more user-friendly/responsive and easier to iterate through changes quickly.
- irunbackwards 13y agoThis is definitely doable -- we've put this in our to-do, thanks for the feedback!
- jwarren 13y agoVery cute! Love the sentence-based construction. This would be really strong if it allowed you to generate more complex queries. For instance, you can't select more than one post status, select a custom post type, or use meta fields as part of the query. I get that it's meant to provide a nice starting point, but value for me (and I get that I might not be a target) would be a natural language abstraction of the more complex queries.
- irunbackwards 13y agoHey jwarren, we're working on making it more complex -- we wanted to get the MVP out for user feedback. We want to add things like support for multiples of the current criteria we have, as well as more advanced queries like custom fields and custom taxonomy.
- zapt02 13y agoYou should check out Views for Wordpress, which does exactly this only the queries actually work inside your application. (Like Drupal views.) http://wp-types.com/home/views-create-elegant-displays-for-your-content/ http://wp-types.com/home/views-create-elegant-displays-for-y...
- shloime 13y agoI could definitely see myself using something like this. It needs some more complex loops, but it's a great MVP. Cheers.
- irunbackwards 13y agoThanks! We plan on adding support for things like custom fields and meta data soon, so stay tuned!
- ereckers 13y agoNot the greatest experience on iPad 2. Back on the desktop, it doesn't seem to clear values, only adds them (I'm playing with chaning posts, page, etc..) Here's a good WP Query resource I've been using to structure marginally complex queries: https://gist.github.com/luetkemj/2023628
- jjsz 13y agoI noticed the Wordpress theme Salient using this. It´s much easier for noobs.
- irunbackwards 13y agoHey! Just checked out Salient, are you referring to the shortcode generator? I've never used the theme, just checking it out on Theme Forest.
- jjsz 13y agoHey, I'm talking about Salient's way of handling the portfolio arrays are the same[0] as the one on this site. [0] http://themenectar.ticksy.com/ticket/46881 http://themenectar.ticksy.com/ticket/46881
- jonheller 13y agoI think this is awesome. Obviously it's not geared towards intermediate or higher level WordPress developers, but for someone like my wife who is just digging into WordPress looping it's a wonderful learning tool.
- ramen 13y agoHere is a library I wrote to make querying WordPress easier: https://github.com/ramen/wp-find https://github.com/ramen/wp-find It has a more conventional builder-style API that may answer the complaints of those wishing for a more straightforward way to write loops.
- irunbackwards 13y agoNeat, starred!
- IgorPartola 13y ago'posts_per_page' => 'all' is not a valid value.
- irunbackwards 13y agoNice catch -- fixed and pushed!
- cmwelsh 13y agoI wrote a WordPress plugin that allows you to use the WP_Query class as an iterator: https://github.com/cmwelsh/zesty-wp-query https://github.com/cmwelsh/zesty-wp-query