How to show all posts of the category in wordpress?

<?php $args = array( ‘category’ => 7, ‘post_type’ => ‘post’ ); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?> <h2><a href=”https://wordpress.stackexchange.com/questions/17496/<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endforeach; ?> just change the category id (number 7) and change the post_type that was in the plugin to learn more about … Read more

Nested custom post types with permalinks

If you want to keep ‘authors’ as the base slug in the permalinks, i.e. example.com/authors/stephen-king/ for the ‘authors’ CPT, example.com/authors/stephen-king/the-shining/ for the ‘books’ CPT and example.com/authors/stephen-king/the-shining/chapter-3/ for the ‘chapters’ CPT, WordPress will think pretty much everything is an ‘authors’ post or a hierarchical child of an ‘authors’ post and, since that is not the case, … Read more

How to connect different CPTs together?

As a programmer, I would start writing my own code to connect my post types. It’s not a quick way, it’s not easy, but it’s a lot of fun. The post types We start by creating two simple post types, Author and Books: add_action(‘init’, ‘p2p2_register_author’); add_action(‘init’, ‘p2p2_register_book’); function p2p2_register_author(){ $labels = array( ‘name’ => ‘Author’, … Read more

Parent child relationship in custom post type

In your register_post_type call, make sure you have these arguments: register_post_type( ‘my_post_type’, array( ‘hierarchical’ => true, ‘public’ => true, ‘rewrite’ => array( ‘slug’ => ‘my_post_type’, ‘with_front’ => false, ), ‘supports’ => array( ‘page-attributes’ /* This will show the post parent field */, ‘title’, ‘editor’, ‘something-else’, ), // Other arguments ) ); Make sure your permalinks … Read more