Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jesper van Engelen

    (@engelen)

    Hi Matt,

    It’s certainly possible to show the post parent in a column. For hierarchical post types (such as the default “Pages”), you can use the column type “Parent” under “Custom”. Could you let me know if you’re able to find it?

    Cheers!
    Jesper

    Thread Starter Mattaton

    (@mattaton)

    Ah okay. I think my setup is a little too complicated for this to work. I’ve had to do some trickery to allow for a post type to have a parent from another post type. In this case, I don’t think your plugin realizes the posts do indeed have parents even though it’s not a hierarchical post type.

    The option you mentioned isn’t there. So, I assume it’s because the post type is not actually set as hierarchical.

    Thanks!

    Plugin Author Jesper van Engelen

    (@engelen)

    Hi Matt,

    For some reason, my second reply from yesterday seems to have disappeared. It’s quite possible that your way of assigning a “parent” allows our plugin to display it in a column. In what way is the post parent stored (as an ID or, for example, as a post title)? Do you know whether it’s stored in a custom field or in another way?

    Cheers!
    Jesper

    Thread Starter Mattaton

    (@mattaton)

    I have cobbled together code by working with those that know more than me on StackExchange, etc. I’m pretty certain it utilizes the post_parent field from the post meta table in the database.

    It basically makes use of the core parent meta box and simple changes the options in the select to that of another post type.

    Here is the code that does the work:

    function episodes_attributes_meta_box($post) {
        $pages = wp_dropdown_pages(
        	array(
        		'post_type' => 'cartoon-series',
        		'selected' => $post->post_parent,
        		'name' => 'parent_id',
        		'show_option_none' => __('Choose a Cartoon Series'),
        		'sort_column'=> 'menu_order, post_title',
        		'echo' => 0
        	)
        );
        if ( ! empty($pages) ) {
            echo $pages;
        } // end empty pages check
    }
    add_action('add_meta_boxes', function() {
        add_meta_box('episodes-parent', 'Cartoon Series', 'episodes_attributes_meta_box', 'episodes', 'side', 'default');
    });

    Plugin Author Jesper van Engelen

    (@engelen)

    Hi Martin,

    That’s quite a hack you’ve got there, to add a post parent box to a post type that is, in fact, not hierarchical :-). I’ve worked out a solution to your problem, which is to override Admin Columns’ check for a post type being hierarchical to enable the post parent column. Could you try adding the following code to your theme’s functions.php file (or, even better, in a plugin dedicated to this kind of additional functionality for your site)?

    <?php
    function myplugin_column_properties( $properties ) {
    	// Check whether the column we're targeting is the post parent column
    	if ( $properties['type'] == 'column-parent' ) {
    		// Make the column available
    		$properties['is_registered'] = true;
    	}
    
    	return $properties;
    }
    add_filter( 'cac/column/properties/storage_key=episodes, 'myplugin_column_properties' );

    Just let me know if it works!

    Cheers!
    Jesper

    Thread Starter Mattaton

    (@mattaton)

    HA! Thanks, Jesper! (It’s Matt, not Martin, by the way ?? )

    I can’t take full credit for the hack I have going. Someone far smarter than me on StackExchange helped me get that working. One of the requirements for it to work was that the post type could NOT be hierarchical. I’m not sure why, but I guess it’s because it causes a conflict when the post typically wants its parent to be of the same post type.

    I’ll try out your bit of code magic and see if it works!

    Thanks!
    Matt

    Thread Starter Mattaton

    (@mattaton)

    Worked perfectly, Jesper!

    Thanks!!!

    Plugin Author Jesper van Engelen

    (@engelen)

    I’m sorry about the misspelling of your name, and I’m glad to hear that I’ve been able to help you! If there’s anything else I can help you with—now or in the future—just let me know.

    If you wouldn’t mind, could you leave a review of our plugin? I would greatly appreciate that! You can leave a review here.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Post Parent?’ is closed to new replies.