I am using posts_groupby filter to group by a custom field my wordpress posts. Is there any way using wp_query and posts_groupby to group my posts using part of a string of the custom field?

Any help appreciated.

  • What do you mean by "group by"? In MySQL, which is what the post_groupby filter is for, it's used for combining results into a single row. It sounds like what you're actually trying to do is to order results by a custom field. Is that right? Can you give an example? – Jacob Peattie Nov 25 '19 at 23:51
  • No i want to group by a part of a string using a custom field in wordpress. For example my posts table custom field have the phrases 'i am not a human today' , 'i am not a human tomorrow' . So i have 2 posts that the custom field has the phrase 'i am not a human'. The difference is that one includes also the word tomorrow and the other the word today. If i use group by i would get two single posts. I want to group by using the part of the string that says 'i am not human' and not the complete phrase. So i can have one single result. Hope you understood. – stefanosn Nov 26 '19 at 0:02
  • What would that result actually be? WP_Query fetches posts from the database, it doesn't make sense to return a single post object that represents more than one post because they've been 'grouped'. I also don't see why you would do this with posts and post meta, can you give an actual use case using WP posts? What is the data you're trying to retrieve? – Tom J Nowell Nov 26 '19 at 1:24
  • Never mind i will find solution. Its difficult to explain. Thanks for your help everyone. – stefanosn Nov 26 '19 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.