• Resolved skyfox2k

    (@skyfox2k)


    I’m not sure why but I have this code:

    [display-posts category=’current’ post_type=’post’ exclude_current=’true’ posts_per_page=’1′ orderby=’date’ include_excerpt=’true’ excerpt_length=’20’ wrapper_class=’post-featured’ image_size=’footer-modules’]

    And I’m sometimes getting PAGES in the results instead of POSTS.

    Any ideas why this would be the case? Also, increasing the strangeness, the category of ‘current’ sometimes brings up unrelated PAGES (again, not POSTS). PAGES that simply aren’t the same category!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    That’s really strange. Do you have any other plugins installed that might be altering queries on your site?

    Have you made any code customizations using the Display Posts filters?

    Can you try changing those single quote marks (‘) to double quote marks (“)?

    Example:

    [display-posts category="current" post_type="post" exclude_current="true" posts_per_page="1" orderby="date" include_excerpt="true" excerpt_length="20" wrapper_class="post-featured" image_size="footer-modules"]

    Thread Starter skyfox2k

    (@skyfox2k)

    Actually, it was updating to your latest code that worked!

    BUT!

    It’s introduced a new bug in that tags are no longer working!

    I’m using tags on pages with this code:

    // add tag and category support to pages
    function tags_categories_support_all() {
      register_taxonomy_for_object_type('post_tag', 'page');
      register_taxonomy_for_object_type('category', 'page');
    }
    
    // ensure all tags and categories are included in queries
    function tags_categories_support_query($wp_query) {
      if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
      if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
    }
    
    // tag and category hooks
    add_action('init', 'tags_categories_support_all');
    add_action('pre_get_posts', 'tags_categories_support_query');

    This was working fine with version 2.9 of the code, but your 2.9.1 that fixes the pages issue, introduces this problem…

    • This reply was modified 7 years, 4 months ago by skyfox2k.
    Thread Starter skyfox2k

    (@skyfox2k)

    The original issue extends to categories too, as with a PAGE category set to: “name”, when I have
    category="name" post_type="post"
    it will only show POSTS with the category “name”.

    Thoughts?

    Plugin Author Bill Erickson

    (@billerickson)

    The code snippet you posted is overriding ANY query that involves a category or tag. So when you are requesting posts with a certain category, your custom code is changing that to “any” post type with that category.

    You should modify your code to this: https://gist.github.com/billerickson/51e289e971a70bfd3f917e3cd0b3e565

    The key is only applying your change if $query->is_main_query(). That ensures it only affects the main query on the page (ex: the tag archive loop) and not custom queries (ex: display posts shortcode).

    For more information, see my article on customizing the main query.

    Thread Starter skyfox2k

    (@skyfox2k)

    Gotcha.

    Using your (really gracious) help didn’t solve the issue entirely, but I discovered the problem:

    TAGS are only showing for PAGES that are *not* CHILDREN of another PAGE. As soon as you add a PARENT PAGE, the CHILD PAGE no longer is displayed by your plugin.

    Perhaps it’s an issue outside of you plugin, I don’t know.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Strange Error: Display Pages not Posts’ is closed to new replies.