WordPress.org

Ready to get started?Download WordPress

Forums

Variables in do_action (6 posts)

  1. Matthew
    Member
    Posted 2 years ago #

    I am working on a modification to the Multipost Mu to enable custom posts. I have the code working pretty well except for he last step of adding the actions, which I would like to run in a loop, instead of hard coding. WordPress is not liking my attempt at entering a variable as the tag parameter.

    if( function_exists( 'get_post_types' ) ){
      function retrievePostTypes() {
      // Retrieve only Custom Post Types. Ignore builtin types.
        $custom_posts = get_post_types( array( 'public' => true,
    				                           'capability_type' => 'post',
    										   '_builtin' => false
    										  ),
    										  'names'
    								  );
    	return $custom_posts;
    	}
    }

    This works great on "add_meta_box".

    $retrieved_types = retrievePostTypes();
    			foreach( $retrieved_types as $custom_post ) {
    				  add_meta_box('HMMPMU_meta', 'Multipost', 'HMMPMU_showSubBlogBoxes', $custom_post, 'side', 'low' );
    
    			}

    This method DOES NOT work on the "do_action" side of things.

    $retrieved_types = retrievePostTypes();
    	foreach( array ($retrieved_types) as $custom_post ) {
    	  add_action( 'publish_' . $custom_post, array(&$hmMultipostMU, 'multiPost'), 1);
    	}

    Any help would be appreciated.

  2. Chee Studio
    Member
    Posted 2 years ago #

    I wish I had a answer for you but I just wanted to bump this because I am in very much need of having Multipost MU use Custom Post Types. And perhaps you figured it out?! :)

  3. Matthew
    Member
    Posted 2 years ago #

    I have Multipost MU working on CPTs but it requires a direct editing of the code. I haven't figured out how to enable it automatically based on registered post types.

    I can post the code on my paste bin and show you what mods I made and what mods you would need to make.

  4. Matthew
    Member
    Posted 2 years ago #

    I think I need to revisit how I build the array based on the registered CPTs.

  5. Chee Studio
    Member
    Posted 2 years ago #

    Sure, that would be great. I really only need it for one Post Type anyway...thanks so much!

  6. Matthew
    Member
    Posted 2 years ago #

    Just add your custom post type name after the "publish_".

    If you registered custom post type "books" your code would look like this.

    add_action( 'publish_books', array(&$hmMultipostMU, 'multiPost'), 1);

    If you update the plugin, beware, it will overwrite your change.

Topic Closed

This topic has been closed to new replies.

About this Topic