• Resolved OG-S

    (@og-s)


    Hi !
    Thank you for this plugin. Everything is working well excepting that order by post_title not working

    $str = "SELECT *
    FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta m1 ON ($wpdb->posts.ID = m1.post_id)
    LEFT JOIN $wpdb->postmeta m2 ON ($wpdb->posts.ID = m2.post_id)
    WHERE (m1.meta_key = 'marque_produit' AND m1.meta_value = 'Berollka Aktiv')
    AND (m2.meta_key = 'type_produit')
    AND $wpdb->posts.post_status = 'publish'
    ORDER BY $wpdb->posts.post_title ASC
    ";
    $result = $wpdb->get_results($str);

    Did I made a mistake?

    Best regards

    https://www.ads-software.com/plugins/qtranslate-x/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Clause

    (@johnclause)

    Yes, because post_title has [:xx] language tags. You need fetch the result unsorted, translate post_title to the language you need, and then sort the table using PHP functions. To translate you may use apply_filter('translate_text', $var, $lang), which is documented in the source code: https://github.com/qTranslate-Team/qtranslate-x/blob/master/inc/i18n-interface.php and referred from https://qtranslatexteam.wordpress.com/interface/.

    Thread Starter OG-S

    (@og-s)

    I have the same problem with

    <?php
    $myposts = get_posts('meta_key=marque_produit&meta_value=
    Etac&post_type=produits&numberposts=-1&offset=$debut&orderby=title&order=ASC');
    foreach($myposts as $post) :

    the order in not working if the title is the same for the different languages.

    The plugin is considering that the Languages are not set.

    Plugin Author John Clause

    (@johnclause)

    Do you mean all fetched titles do not have multilingual values or some of them do and some do not? Anyway, the answer is the same – sort outside of db call. If languages are not set on all of them, then it should work – check the syntax then and troubleshoot it appropriately. Maybe “title” needs to be “post_title”, for example?

    In theory, you may extract language needed in a separate additional field using regular expression and string manipulation and sort by that field, but I am not sure which way will be quicker. You need to translate it anyway later, I guess, so why not to sort it later too.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘order by post_title not working’ is closed to new replies.