link posts to custom post type

admin2025-01-07  5

I have a custom post type 'books' which I store different custom fields of information about books.

I want to use posts and link the posts I write (in categories such as news, or offers) to the books.

For example, when the user is viewing the book information page, I want to be able to display all the posts in news category related to that book.

I was able to do this using a custom field and assigning the book id to the news. But what if I have a news that's related to a lot of books?

Is there any way to file all the Custom Post titles to a taxonomy? What's the best way to do this?

I have a custom post type 'books' which I store different custom fields of information about books.

I want to use posts and link the posts I write (in categories such as news, or offers) to the books.

For example, when the user is viewing the book information page, I want to be able to display all the posts in news category related to that book.

I was able to do this using a custom field and assigning the book id to the news. But what if I have a news that's related to a lot of books?

Is there any way to file all the Custom Post titles to a taxonomy? What's the best way to do this?

Share Improve this question asked Apr 2, 2013 at 21:40 FixtreeFixtree 11 silver badge2 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

Try Posts to Posts Plugin

This plugin allows you to create many-to-many relationships between posts of any type: post, page, custom etc. A few example use cases:

  • manually curated lists of related posts
  • post series
  • products connected to retailers
  • etc.

Additionally, you can create many-to-many relationships between posts and users. So, you could also implement:

  • favorite posts of users
  • multiple authors per post
  • etc.

Creating these links and displaying them on any desired page with a widget or shortcode can be easily done with a plugin called Sub Posts. It's not a free plugin, but it will do exactly what you're asking. You can find more information at www.subposts.com

In your functions.php file, you can register a new taxonomy and related with your custom post type, for example

create a custom post type: https://codex.wordpress.org/Function_Reference/register_post_type

register_post_type('books',
      array(
        'labels' => array(
          'name' => __('Books', 'sc'),
          'singular_name' => __('Book', 'sc')
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'books'),
        'supports' => array('title', 'editor', 'author', 'thumbnail')
      )
    );

Create a custom taxonomy (similar to categories) https://codex.wordpress.org/Function_Reference/register_taxonomy

register_taxonomy(
      'gender',
      'books',// your custom post name
      array(
        'label' => __('Gender', 'sc'),
        'rewrite' => array( 'slug' => 'gender' ),
        'show_ui' => true,
        'public' => true,
        'show_in_quick_edit' => false,
        'meta_box_cb' => false,
        'show_in_menu'=>true,
        'show_in_nav_menus' => true,
        'query_var' => true,
      )
    );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736253443a124.html

最新回复(0)