• Hello, I would like to make a special query in WordPress.

    I would like my function gengoGetAPost to find (if exists) the translated post of a given post_id.

    Posts are in the “$wpdb->posts” table.
    Posts with their post_id, language_id and translation_group are in “$gengo->post2lang_table”.

    If I have 2 posts :

    |POST_ID|LANGUAGE ID|TRANSLATION_GROUP|
        17        1               5
        23        2               5

    I would like that gengoGetAPost(17,2) returns me the row of the post #23 in the $wpdb->posts table.

    Could you help me ?
    Here’s my first draft (not working), but I don’t know what to do now…

    function gengoGetAPost($post,$lang) {
    	global $gengo, $wpdb;
    
    	$language_ids = 2;
    	$query = "SELECT p.* FROM $wpdb->posts AS p INNER JOIN $gengo->post2lang_table AS p2l ON p.ID = p2l.post_id WHERE p2l.translation_group=$lang AND p2l.post_id='".$post."' LIMIT 1";
    	echo $query;
    	return ($result = $wpdb->get_row($query)) ? $result : NULL;
    }
Viewing 1 replies (of 1 total)
  • Thread Starter grosbouff

    (@grosbouff)

    I have this

    function gengoGetAPost($post) {
    	global $gengo, $wpdb;
    	$language_ids = implode(',', $gengo->language_preference_id);
    	$query = "SELECT p . * FROM $wpdb->posts AS p INNER JOIN $gengo->post2lang_table AS p2l ON p.ID = p2l.post_id WHERE p2l.translation_group = (SELECT translation_group FROM $gengo->post2lang_table WHERE post_id = '".$post."' ) AND p2l.language_id IN ($language_ids) LIMIT 1";
    	$result = $wpdb->get_row($query)
    	return ($result = $wpdb->get_row($query)) ? $result : NULL;
    }

    in phpmyadmin, it works, giving me the good (translated post). But once I call the function in wordpress, it’s not showing the good one… ?

Viewing 1 replies (of 1 total)
  • The topic ‘special query (gengo wordpress) with inner join’ is closed to new replies.