Timeline for Using DISTINCT in wp_query
Current License: CC BY-SA 3.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 9, 2014 at 15:33 | comment | added | phatskat | @Pim Thanks for this answer, just what I needed on a project | |
May 22, 2014 at 21:17 | comment | added | marcelo2605 | You're right. So I transfrom states and cities in taxonomies. Thanks. | |
May 22, 2014 at 21:05 | comment | added | Pim | And what is the problem exactly? That is the expected result of that query. The query isn't returning states, you have 3 stores so it returns 3 results. You are querying posts. How would you want it to behave? Only return one post per state? Based on what conditions? Your question is too unclear. | |
May 22, 2014 at 20:46 | comment | added | marcelo2605 | For example: I have three store. One on SP and two on MG. The query return SP, MG, MG. | |
May 22, 2014 at 20:44 | comment | added | marcelo2605 | get_custom_filed() is a function to retrieve post meta values. | |
May 22, 2014 at 20:35 | comment | added | Pim | Does your query actually produce duplicate "store" posts? Or is the meta just being repeated? | |
May 22, 2014 at 20:27 | comment | added | Pim |
With your updated code, it's a different story entirely... you say the state is being repeated right? So no need for "distinct" posts. But what is get_custom_field() ? That doesn't seem very standard.
|
|
May 22, 2014 at 19:49 | comment | added | marcelo2605 | I add the filter as you said (see above) but nothing happens. | |
May 22, 2014 at 19:37 | comment | added | Pim |
Try to include it right before the query, then call remove_filter('posts_distinct', 'search_distinct'); right after the loop is finished.
|
|
May 22, 2014 at 19:29 | comment | added | marcelo2605 | I will use this query in a simple loop. | |
May 22, 2014 at 19:20 | comment | added | Pim | You'd need to combine it with wordpress conditionals, depending on where you want to use the query (for instance is_post_type_archive('store') ), or you could include the filter directly in your template so it's only called there. | |
May 22, 2014 at 19:17 | comment | added | marcelo2605 | Hey Pim. How can I connect this filter with the query? | |
May 22, 2014 at 19:15 | history | answered | Pim | CC BY-SA 3.0 |