0

The filter code below is from Themeskingdom Exclusy theme. It makes a sql query for posts ids and then queries the taxonomy terms associated with those posts. I then uses isotope jquery plugin to serve a list of years (the terms) that the user can filter the posts by. My problem is that I'm creating a bilingual site with Polylang. And, although, when I'm in the english version of the site, I get just a list of english language posts, I get all the years available for filtering, from both english and native language posts. I believe I must replace that sql query with a query that takes polylang's lang parameter, and enclose it with a current locale conditional. But I need a query function that can return ids so I don't change the original too much. Or is there a simpler way? Thank you,

<div class="gallery-filter left">
            <span><?php _e('Filter:', tk_theme_name) ?></span>
            <a href="#" data-filter="*" class="active-project active"><?php _e('All', tk_theme_name) ?></a>
            <?php
            global $wpdb;
            $gallery_orderby = get_theme_option(tk_theme_name . '_gallery_gallery_orderby');
            $gallery_order = get_theme_option(tk_theme_name . '_gallery_gallery_order');
            $post_type_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'texto' AND post_status = 'publish'");
            if (!empty($post_type_ids)) {
                $post_type_cats = wp_get_object_terms($post_type_ids, 'ano', array('orderby' => 'name', 'order' => 'DESC', 'fields' => 'ids', 'hide_empty' => true ));
                if ($post_type_cats) {
                    $post_type_cats = array_unique($post_type_cats);
                }
            }
            $include_category = null;
            if (!empty($post_type_ids)) {
                foreach ($post_type_cats as $category_list) {
                    $cat = $category_list . ",";
                    $include_category = $include_category . $cat;
                    $cat_name = get_term($category_list, 'ano');
                    ?>
                    <a href="#" data-filter="<?php echo '.class-' . $category_list ?>"><?php echo $cat_name->name ?></a>
                <?php }
            } ?>
</div><!--/gallery-filter-->
1

I got it. With help from this answer: get all posts ID from a category

$post_type_ids = get_posts(array(
'numberposts'   => -1, // get all posts.
'post_type' => 'texto',
'fields'        => 'ids', // Only get post IDs
  ));          

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.