WordPress.org

Forums

Post Type Switcher
Advanced filtering (restrict to specific CPT) (2 posts)

  1. ratsoid
    Member
    Posted 2 years ago #

    Hello,
    I'm building the intranet for my company and we ended up having a huge portal. One of the options is for the employees to submit News items from the frontend. When they submit it, the entry is set as a draft in the "news" post type. We also have a blog section, which uses the normal posts (CPT 'post'). Well, since some submited news item might go better into the blog section, I opted to use a plugin that makes it easy for the administrators of the move them in the blog, thus Post Type Switcher.

    The problem that I'm having is, I want to restrict the functionality of the plugin to just 'news' and 'post', and not have it displayed on other post types (we have many), and restrict the ability to switch only between news and posts.

    I ended up using this code and a jQuery to hide the option from the quickedit box:

    add_filter( 'pts_post_type_filter', 'pts_disable');
    function pts_disable( $args ) {
    $postType = get_post_type();
    if( 'post' === $postType ) :
    $args = array(
    'name' => 'news'
    );
    elseif ( 'news' == $postType ) :
    $args = array (
    'name' => 'post'
    );
    else :
    $args = array (
    'name' => 'none'
    );
    endif;
    return $args;
    }

    Basically, this code is crap. When editing a news type, after updating, it moves the news to posts by default. There isn't a lot of documentations of about this filter, so I don't know how to achieve everything that I want. Currently, I removed the function and just flooded the backend .js with jQuery functions to hide everything that isn't "news" or "post", and hide the quickedit option to any post types that aren't 'news' or 'post'. This option works, of course, but it's very nasty and would prefer something default.

    Can you guys help me out and try to figure out if I can do everthing with pts_post_type_filter?

    Also, johnjamesjacoby > yoast :-)
    Have a great one guys

    http://wordpress.org/extend/plugins/post-type-switcher/

  2. ratsoid
    Member
    Posted 2 years ago #

    This is how I 'fixed' it with jQuery (added backend script):

    jQuery('.inline-edit-row #pts_post_type').parents('.inline-edit-col-right').hide();

    jQuery('#pts_post_type option').each(function(){
    var _post_type = jQuery('#post_type');
    if(jQuery(this).val() !== 'news' && jQuery(this).val() !== 'post') {
    jQuery(this).hide();
    }

    if(_post_type.val() !== 'news' && _post_type.val() !== 'post') {
    jQuery(this).parents('.post-type-switcher').hide();
    }
    });

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Post Type Switcher
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.