How do I get all the posts where the value in wp_postmeta.meta_value is the selected city? I now use the code below, but this doesn't work 100% because I use the LIKE method. So if I select "York" I get "York" and "New York". The meta_value is sometimes translated with qtranslate-x and somethimes not. So

I have in the database:

meta_value = 'York'

meta_value = '[:en]New York[:es]Nueva York[:]'

The english value is always filled.

$metaFilter = array(
        'city_clause' => array(
            'key' => 'city',
            'value' => '' . $selectedCity,
            'compare' => 'LIKE'
$mypost = array(
        'post_type' => 'post',
        'paged' => get_query_var('paged'),
        'posts_per_page' => 4,
        'meta_query' => $metaFilter,
        'orderby' => array(
            'country_clause' => 'ASC',
            'city_clause' => 'ASC',
  • Don’t use qtranslate - it stores many languages (so many different posts) as one record in DB - and that makes it very hard (or nearly impossible) to perform many searches (as you’ve now discovered). – Krzysiek Dróżdż Feb 16 '19 at 8:02
  • Thanks, the site is already running with qtranslate-x, was thinking about using REGEX for this. – Cerveser Feb 16 '19 at 18:32

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.