function bogo_adjacent_post_where($where, $in_same_term, $excluded_terms) { global $wpdb; $post = get_post(); if ($post && bogo_is_localizable_post_type(get_post_type($post))) { $locale = bogo_get_post_locale($post->ID); $where .= " AND (1=0"; $where .= $wpdb->prepare(" OR postmeta_bogo.meta_value LIKE %s", $locale); if (bogo_is_default_locale($locale)) { $where .= " OR postmeta_bogo.meta_id IS NULL"; } $where .= ")"; } return $where; }
function bogo_unique_post_slug($slug, $post_id, $status, $type, $parent, $original) { global $wp_rewrite; if (!bogo_is_localizable_post_type($type)) { return $slug; } $feeds = is_array($wp_rewrite->feeds) ? $wp_rewrite->feeds : array(); if (in_array($original, $feeds)) { return $slug; } $locale = bogo_get_post_locale($post_id); if (empty($locale)) { return $slug; } $args = array('posts_per_page' => 1, 'post__not_in' => array($post_id), 'post_type' => $type, 'name' => $original, 'lang' => $locale); $hierarchical = in_array($type, get_post_types(array('hierarchical' => true))); if ($hierarchical) { if (preg_match("@^({$wp_rewrite->pagination_base})?\\d+\$@", $original)) { return $slug; } $args['post_parent'] = $parent; } $q = new WP_Query(); $posts = $q->query($args); if (empty($posts)) { $slug = $original; } return $slug; }
function bogo_get_local_post($post_id) { global $wpdb; if (is_admin() || empty($post_id)) { return $post_id; } $post_type = get_post_type($post_id); if (!post_type_exists($post_type) || !bogo_is_localizable_post_type($post_type)) { return $post_id; } $locale = get_locale(); if (bogo_get_post_locale($post_id) == $locale) { return $post_id; } $original = get_post_meta($post_id, '_original_post', true); if (empty($original)) { $original = $post_id; } $q = "SELECT ID FROM {$wpdb->posts} AS posts"; $q .= " LEFT JOIN {$wpdb->postmeta} AS pm1"; $q .= " ON posts.ID = pm1.post_id AND pm1.meta_key = '_original_post'"; $q .= " LEFT JOIN {$wpdb->postmeta} AS pm2"; $q .= " ON posts.ID = pm2.post_id AND pm2.meta_key = '_locale'"; $q .= " WHERE 1=1"; $q .= $wpdb->prepare(" AND post_type = %s", $post_type); $q .= $wpdb->prepare(" AND (ID = %d OR pm1.meta_value = %d)", $original, $original); $q .= " AND (1=0"; $q .= $wpdb->prepare(" OR pm2.meta_value LIKE %s", $locale); $q .= bogo_is_default_locale($locale) ? " OR pm2.meta_id IS NULL" : ""; $q .= ")"; $translation = absint($wpdb->get_var($q)); if ($translation) { return $translation; } return $post_id; }