WordPress.org

Forums

Category Posts Widget
Add Support for selecting custom post types (6 posts)

  1. jessecd
    Member
    Posted 3 years ago #

    Any chance you'd be interested in adding support to select from custom post types?
    Here's an overview of changes
    $cat_posts query would be changed to add "&post_type=", as shown below:

    // Get array of post info.
      $cat_posts = new WP_Query(
        "showposts=" . $instance["num"] .
        "&cat=" . $instance["cat"] .
        "&orderby=" . $sort_by .
        "&order=" . $sort_order .
        "&post_type=" . $instance['post_types']
      );

    Category Dropdown would add a "no category" option and an explanation of how to use. (there is an issue when you attempt to use "no category" and the post type since posts default to uncategorized - or mine do at least. I'm not positive this is always the case.).
    in function form($instance), edit the category dropdown to:

    <label>
      <?php _e( 'Category' ); ?>:
      <?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"], 'show_option_none' => 'No Category' ) ); ?>
      <?php _e( '<p><em>If displaying the "Post" post type, you cannot select "no category"</em></p>' ); ?>
    </label>

    And, finally, a post_type dropdown would be added. Currently this only accepts 1 post type, but I'm sure it could be tweaked to accept multiple post types.
    In function form($instance), add the following:

    <p>
     <label for="<?php echo $this->get_field_id('post_types'); ?>">
      <?php _e('Post Type: '); ?>
        <select name="<?php echo $this->get_field_name('post_types'); ?>" id="<?php echo $this->get_field_id('post_types'); ?>">
          <?php
            $post_types = get_post_types('', 'names');
            foreach ($post_types as $type):
              echo '<option value=' . $type . '' .  selected( $instance["post_types"], $type ) . '>' . $type . '</option>';
            endforeach; ?>
        </select>
     </label>
    </p>

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

  2. jessecd
    Member
    Posted 3 years ago #

    Anybody have thoughts on this? I think people are working with custom post types so often that it just doesn't make sense to restrict this functionality to posts.

    Anybody agree or disagree? Have I posted in the wrong spot? I'm not sure what the usual avenue would be for getting in touch with the author about potentially including these changes.

  3. sjcallender
    Member
    Posted 2 years ago #

    Thanks for this! Exactly what I was looking for.

  4. poisoned.eden
    Member
    Posted 2 years ago #

    This is absolutely brilliant - such a perfect and simple fix that extends the plugins capabilities no end. Thank you.

    To the developer - please include this in the plugin.

  5. PinkishHue
    Member
    Posted 2 years ago #

    Absolutely agree, this would be a great addition to this plugin :)

    I'm hesitant to make edits to plugins as once a site is handed over to a client they might update it in the future and *poof*, the changes are gone!

  6. slyguy67
    Member
    Posted 2 years ago #

    Thank you for this - very helpful.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Category Posts Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic