WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Widget
[resolved] Make Post Type Public (8 posts)

  1. jonahcoyote
    Member
    Posted 5 months ago #

    Hi there,

    Please make the content_block post type public, offer an option for this or provide a filter so it can be done without hacking the core code. I love this plugin and use it frequently and one of the first things I always do is set it to be public.

    Many thanks,
    Jonah

    https://wordpress.org/plugins/custom-post-widget/

  2. Johan van der Wijk
    Member
    Plugin Author

    Posted 5 months ago #

    HI Jonah, I would be happy to provide a filter for making the content_block post type public in specific cases. Could you provide a code suggestion for implementing this?

  3. jonahcoyote
    Member
    Posted 5 months ago #

    Hi Johan,

    Here you go:
    In /wp-content/plugins/custom-post-widget/post-widget.php:

    // Create the Content Block custom post type
    add_action( 'init', 'my_content_block_post_type_init' );
    
    function my_content_block_post_type_init() {
    	$labels = array(
    		'name' => _x( 'Content Blocks', 'post type general name', 'custom-post-widget' ),
    		'singular_name' => _x( 'Content Block', 'post type singular name', 'custom-post-widget' ),
    		'plural_name' => _x( 'Content Blocks', 'post type plural name', 'custom-post-widget' ),
    		'add_new' => _x( 'Add Content Block', 'block', 'custom-post-widget' ),
    		'add_new_item' => __( 'Add New Content Block', 'custom-post-widget' ),
    		'edit_item' => __( 'Edit Content Block', 'custom-post-widget' ),
    		'new_item' => __( 'New Content Block', 'custom-post-widget' ),
    		'view_item' => __( 'View Content Block', 'custom-post-widget' ),
    		'search_items' => __( 'Search Content Blocks', 'custom-post-widget' ),
    		'not_found' =>  __( 'No Content Blocks Found', 'custom-post-widget' ),
    		'not_found_in_trash' => __( 'No Content Blocks found in Trash', 'custom-post-widget' ),
    		'parent_item_colon' => ''
    	);
    	$content_block_public = false;
    	$options = array(
    		'labels' => $labels,
    		'public' => apply_filters( 'content_block_post_type', $content_block_public ),
    		'publicly_queryable' => false,
    		'exclude_from_search' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'menu_position' => null,
    		'supports' => array( 'title','editor','revisions','thumbnail','author' )
    	);
    	register_post_type( 'content_block',$options );
    }

    ...and then the working filter:

    function filter_content_block_init() {
    	$content_block_public = true;
    	return $content_block_public;
    }
    add_filter('content_block_post_type','filter_content_block_init');

    Might not be the most elegant (I'm no PHP pro) but it works!

  4. Johan van der Wijk
    Member
    Plugin Author

    Posted 5 months ago #

    Hi Jonah,

    I have updated the plugin with the suggested code. Could you please install and test this new version of the plugin: http://downloads.wordpress.org/plugin/custom-post-widget.2.5.3.zip

    Please let me know if this works!

  5. jonahcoyote
    Member
    Posted 4 months ago #

    Hey Johan,

    Looks good to me, thanks for adding it!

    - Jonah

  6. Johan van der Wijk
    Member
    Plugin Author

    Posted 4 months ago #

    Great, I have just released the new version.

  7. Peter
    Member
    Posted 1 month ago #

    Hi Jonah, Johan,

    thanks but it doesn't work for me. I have VC and Custom Post Widget installed - added the function_ .. to my functions.php but I still do not see the custom posts available to select from in the visual composer. What am I doing wrong?

    Also - other plugins that have WP widgets do not appear in the visual composer by default - any idea?

    Thanks in advance,
    Seb

  8. Dan Knauss
    Member
    Posted 1 month ago #

    Thanks guys, this was helpful.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.