Support » Plugins and Hacks » Hacks » distinct meta_value on wp_query

distinct meta_value on wp_query

  • pettedemon


    I can select the distinct value in my custom query?

    $filtra_categorie = array(
    	'cat' => '4',
    	'meta_key' => 'categoria',
    	'orderby' => 'meta_value',
    	'order'    => 'ASC',
    	'posts_distinct' => 'meta_key'

Viewing 3 replies - 1 through 3 (of 3 total)
  • bcworkz


    wp_Query has a bunch of filters you can hook to modify the query before it is run, I’m sure you can slip in DISTINCT using one of them. You cannot do it from the main arguments array.



    How can I apply the filter only for my select query?



    Ah, good question. You recognized the filter fires for every single query, no matter for what purpose.

    Ideally, your filter function would check for some defining characteristic in the passed query object that makes your query unique amongst all others. Perhaps setting a global variable would help with this identification. Or your main process might be able to add the filter just before the query is defined, then remove it immediately afterwards. I’ve not done this last idea, so I cannot be sure it would work properly. It would be a powerful technique if it does work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘distinct meta_value on wp_query’ is closed to new replies.