gengo get-a-post function
-
I wrote a function in gengo_extra_functions.php, to be able to catch a translated post from an ID; sort of get-a-post plugin.
If the function can’t find a translation, it shows the default post.// Sponsored by Gordie Lachance // Outputs the translation of the post ID. function gengoGetAPost($monpost) { global $post, $gengo, $wpdb; $now = current_time('mysql'); $where_posts = "WHERE p.post_date <= '$now' AND p.post_status = 'publish'"; $language_ids = implode(',', $gengo->language_preference_id); $post = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p INNER JOIN $gengo->post2lang_table AS p2l ON p.ID = p2l.post_id INNER JOIN $gengo->post2lang_table AS p3l ON p3l.post_id='".$monpost."' ".$where_posts." AND p2l.translation_group=p3l.translation_group AND p2l.language_id IN ($language_ids) LIMIT 1"); if (!$post) { // if there is no translation, show the original post $where_posts .= " AND p.id='".$monpost."'"; $post = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p ".$where_posts." LIMIT 1"); } get_post_custom($post->ID); setup_postdata($post); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘gengo get-a-post function’ is closed to new replies.