WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Popular Posts
Excluded Catagories excludes posts in multiple categories (4 posts)

  1. Texiwill
    Member
    Posted 4 years ago #

    Hello,

    Could Excluded Catagories not exclude a post that is actually tied to Multiple catagories where 1 is actually the category to include?

    I.e. I have posts in Cat1, Cat2, Cat3 and am excluding Cat2 and Cat3. I would still expect this post to be seen as it is in Cat1.

    Thanks,
    Edward

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. H├ęctor Cabrera
    Member
    Plugin Author

    Posted 4 years ago #

    Hi Edward,

    You said it yourself: problem is that this post is tied to several categories. The query used for this simply filters out all post that belong to the specified categories, it doesn't detect wether it also belongs or not to an allowed category. The Exclude Category feature isn't that smart yet.

    I might try and fix this in a future version of my plugin, however for now can't promise you anything.

  3. Texiwill
    Member
    Posted 4 years ago #

    Hello,

    What about adding a 'cat_to_include' type of approach instead. I want only one of my X categories....

    Thoughts?

  4. Texiwill
    Member
    Posted 4 years ago #

    Here is a diff that implements 'cats-to-include':

    148,149d147
    <                       $instance['include-cats']['active'] = $new_instance['include-cats'];
    <                       $instance['include-cats']['cats'] = empty($new_instance['included']) ? '' : (ctype_digit(str_replace(",", "", $new_instance['included']))) ? $new_instance['included'] : '';
    203,206d200
    <                               'include-cats' => array(
    <                                       'active' => false,
    <                                       'cats' => ''
    <                               ),
    286,293d279
    <             <input type="checkbox" class="checkbox" <?php echo ($instance['include-cats']['active']) ? 'checked="checked"' : ''; ?> id="<?php echo $this->get_field_id( 'include-cats' ); ?>" name="<?php echo $this->get_field_name( 'include-cats' ); ?>" /> <label for="<?php echo $this->get_field_id( 'include-cats' ); ?>"><?php _e('Include categories', 'wordpress-popular-posts'); ?></label> <small>[<a href="<?php echo bloginfo('url'); ?>/wp-admin/options-general.php?page=wordpress-popular-posts/wordpress-popular-posts.php">?</a>]</small><br />
    <             <?php if ($instance['include-cats']['active']) : ?>
    <             <fieldset class="widefat">
    <                 <legend><?php _e('Categories to include', 'wordpress-popular-posts'); ?></legend>
    <                 &nbsp;&nbsp;<label for="<?php echo $this->get_field_id( 'included' ); ?>"><?php _e('ID(s) (comma separated, no spaces):', 'wordpress-popular-posts'); ?></label><br />&nbsp;&nbsp;<input id="<?php echo $this->get_field_id( 'included' ); ?>" name="<?php echo $this->get_field_name( 'included' ); ?>" value="<?php echo $instance['include-cats']['cats']; ?>" class="widefat" style="width:150px" /><br /><br />
    <             </fieldset>
    <             <?php endif; ?>
    <             <br />
    608,627d593
    <
    <                       if ( $instance['include-cats']['active'] && !empty($instance['include-cats']['cats']) ) {
    <                               $include = " AND $wpdb->posts.ID IN (
    <
    <                                                       SELECT  object_id
    <                                                       FROM    $wpdb->term_relationships AS r
    <                                                                       JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
    <                                                                       JOIN $wpdb->terms AS t ON t.term_id = x.term_id
    <                                                       WHERE   x.taxonomy = 'category'
    <                                                                       AND object_id IN
    <                                                                          (
    <                                                                               SELECT object_id
    <                                                                               FROM $wpdb->term_relationships AS r
    <                                                                               JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
    <                                                                               JOIN $wpdb->terms AS t ON t.term_id = x.term_id
    <                                                                               WHERE   x.taxonomy = 'category'
    <                                                                               AND t.term_id IN  (".$instance['include-cats']['cats']."))) ";
    <                       } else {
    <                               $include = "";
    <                       }
    629c595
    <                       $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts $join WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND $range $force_pv $nopages $include GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");
    ---
    >                       $mostpopular = $wpdb->get_results("SELECT $wpdb->posts.ID, $wpdb->posts.post_title $fields FROM $wpdb->posts $join WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' AND $range $force_pv $nopages $exclude GROUP BY $wpdb->posts.ID ORDER BY $sortby DESC LIMIT " . $instance['limit'] . "");
    1034d999
    <                               'cats_to_include' => '',
    1078,1081d1042
    <                               'include-cats' => array(
    <                                       'active' => empty($cats_to_include) ? false : (ctype_digit(str_replace(",", "", $cats_to_include))) ? true : false,
    <                                       'cats' => empty($cats_to_include) ? '' : (ctype_digit(str_replace(",", "", $cats_to_include))) ? $cats_to_include : ''
    <                               ),
    1198c1159
    < */
    ---
    > */

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic