Support » Plugins and Hacks » [Resolved] Query posts by category

[Resolved] Query posts by category

  • Hi,

    I’m a noob programmer and I’ve developed a theme for a friend. Everything works ok, except when I try to query posts by category. I have translated the categories but doesn’t seem to be working. Is there a specific way to make it work with Polylang? Thanks! Awesome plugin by the way!


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby


    Could you explain exactly the result you expect and how you try to do it?

    Yes. Sorry, I should have been more specific.

    I’ve created a one-page only theme and I’m trying to display posts with different categories. I’m using the following code:

    if ( have_posts() ) : while( have_posts() ) : the_post();
    <div class="span3">
         <div class="pic">
              <?php if (( function_exists('has_post_thumbnail') ) && ( has_post_thumbnail() )) {
                         } else { ?>
                              <img src="<?php echo get_template_directory_uri(); ?>/img/no-thumbnail.jpg" width="260" height="260">
                         <?php } ?>
         <div class="id">
              <h3><?php the_title(); ?></h3>
              <?php the_content(); ?>
    <?php endwhile; else: ?>
    <p><?php _e( 'No content was found', 'criativia' ); ?></p>
    <?php endif; ?>

    The problem is that the posts are not translated if I use query_posts();. If I comment the query line they are translated. Perhaps there is another way to make it work or probably I’m doing something wrong. Thanks in advance! x)

    Plugin Author Chouby


    When you query the category ‘team’, you query the language associated to this category which is unique. If you want to query the category ‘team’ or its translation depending on the language, you have several solutions.

    1. Use the function ‘pll_get_term’ provided by Polylang (which will translates the category). For example:

    $cat = get_category_by_slug('team'); // get category object
    $cat = pll_get_term($cat->term_id); // get id of translation

    2. Use a functionnality I am currently developing: Paste http://pastebin.com/utLLn1cu in a new php file which you will upload in your plugin directory and activate the newly created plugin. It should automatically do the category translation

    Everything’s working beautifully now. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Query posts by category’ is closed to new replies.