Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You designate the parent/child relationships when actually creating the posts in the post type.

    Thread Starter stug2013

    (@stug2013)

    Sorry Michael, I know I’m being thick but can you run that by me a different way. I see now where you mean in the attributes box of the post but I think I am going about creating the custom post types in the wrong way because I don’t get what I want as an option. Perhaps if I explain what I want to do you would be kind enough to point me in the right direction. I think I am getting in a mess as to what should be a custom post type and a taxonomy.
    Within my website which has normal blog posts on it I am creating what I am calling a magazine with regular posts from 5 different people, like a column in a newspaper. Each column has a name, lets say one in ‘chocolate recipes’. what I am trying to achieve is to have these as columns collected within the magazine custom post type and then the posts collected under each relevant column. So then the address bar would look something like: https://www.mysite/magazine/chocolate-recipes/chocolate-chilli.html

    thanks for your help
    Stu

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi Stu,

    Thank you for the more information, it does actually help.

    It sounds like “Magazine” should be the post type, and then you could create a “columns” taxonomy and “chocolate recipes” would be one of the terms in that taxonomy.

    If I recall right, that should facilitate urls that equal out to https://www.mysite/magazine/chocolate-recipes/chocolate-chilli/. However, I can’t recall exactly how easy it is to get both the post type slug and the taxonomy terms in the permalink at the same time. That one may take a little bit more work.

    Hope that helps clear up some confusion.

    Thread Starter stug2013

    (@stug2013)

    Thanks Michael, I will give it a go.

    Hi Michael,

    Not sure whether this is tackled somewhere but can’t find the solution after loooong hours of searching.

    I used the plugin Custom Post Types UI to create a custom post type. Now a new archive page has been created. Then I created posts and child posts that are assigned to their parent post.

    Now, on the archive page, both the parent posts and the child posts are displayed in a list (this is a list of the posts that I created). Is there a way to display only the parent posts and not the child posts?

    Many thanks for your reply:)

    Fred

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    This should work, tested myself. Make sure to replace “ENTER POST TYPE SLUG HERE” with your actual post type slug you want this for. Add the snippet and amend it in your theme’s functions.php file.

    function fredw_cptui_hide_child_posts( $query ) {
    	if ( !$query->is_main_query() || is_admin() ) {
    		return;
    	}
    
    	if ( is_post_type_archive( 'ENTER POST TYPE SLUG HERE' ) ) {
    		$query->set( 'post_parent', '0' );
    	}
    }
    add_action( 'pre_get_posts', 'fredw_cptui_hide_child_posts' );
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘custom posts hierarchy’ is closed to new replies.