CPTs relationship

Question

I have two CPT – project and publication. Is there a way to “connect” those CPSs to the permalink looks like:

foo.com/project/lorem/publication/ -> archive-publication.php
foo.com/project/lorem/publication/ipsum -> single-publication.php

So one project can have X publications. Something like CRUD logic but just the “Read” part (all publications and a single one).

My functionsp.php:

function publications_init() {

  $labels = array(
    'name'                => _x( 'Publications', 'Post Type General Name', 'cornell' ),
    'singular_name'       => _x( 'Publication', 'Post Type Singular Name', 'cornell' ),
    'menu_name'           => __( 'Publications', 'cornell' ),
    'parent_item_colon'   => __( 'Parent Publication', 'cornell' ),
    'all_items'           => __( 'All Publications', 'cornell' ),
    'view_item'           => __( 'View Publication', 'cornell' ),
    'add_new_item'        => __( 'Add New Publication', 'cornell' ),
    'add_new'             => __( 'Add New', 'cornell' ),
    'edit_item'           => __( 'Edit Publication', 'cornell' ),
    'update_item'         => __( 'Update Publication', 'cornell' ),
    'search_items'        => __( 'Search Publication', 'cornell' ),
    'not_found'           => __( 'Not Found', 'cornell' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'cornell' )
  );

  $args = array(
    'label'               => __( 'publications', 'cornell' ),
    'description'         => __( 'Publication news and reviews', 'cornell' ),
    'labels'              => $labels,
    // Features this CPT supports in Post Editor
    'supports'            => array( 'title', 'editor', 'thumbnail', /* 'comments', 'revisions', 'custom-fields', 'excerpt', 'author' */),
    // You can associate this CPT with a taxonomy or custom taxonomy. 
    // 'taxonomies'          => array( 'genres' ),
    /* A hierarchical CPT is like Pages and can have
    * Parent and child items. A non-hierarchical CPT
    * is like Posts.
    */ 
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page'
  );

  register_post_type( 'publication', $args );
}

add_action( 'init', 'publications_init', 0 );

function projects_init() {

  $labels = array(
    'name'                => _x( 'Projects', 'Post Type General Name', 'cornell' ),
    'singular_name'       => _x( 'Project', 'Post Type Singular Name', 'cornell' ),
    'menu_name'           => __( 'Projects', 'cornell' ),
    'parent_item_colon'   => __( 'Parent Project', 'cornell' ),
    'all_items'           => __( 'All Projects', 'cornell' ),
    'view_item'           => __( 'View Project', 'cornell' ),
    'add_new_item'        => __( 'Add New Project', 'cornell' ),
    'add_new'             => __( 'Add New', 'cornell' ),
    'edit_item'           => __( 'Edit Project', 'cornell' ),
    'update_item'         => __( 'Update Project', 'cornell' ),
    'search_items'        => __( 'Search Project', 'cornell' ),
    'not_found'           => __( 'Not Found', 'cornell' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'cornell' )
  );

  $args = array(
    'label'               => __( 'projects', 'cornell' ),
    'description'         => __( 'Project news and reviews', 'cornell' ),
    'labels'              => $labels,
    // Features this CPT supports in Post Editor
    'supports'            => array( 'title', 'editor', 'thumbnail', 'excerpt' /* 'comments', 'revisions', 'custom-fields', 'author' */),
    // You can associate this CPT with a taxonomy or custom taxonomy. 
    // 'taxonomies'          => array( 'genres' ),
    /* A hierarchical CPT is like Pages and can have
    * Parent and child items. A non-hierarchical CPT
    * is like Posts.
    */ 
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page'
  );

  register_post_type( 'project', $args );
}

add_action( 'init', 'projects_init', 0 );

I see that ACF has Post Object so maybe somehow with that?

0
, , Vucko 2 years 2019-11-25T07:59:12-05:00 0 Answers 84 views 0

Leave an answer

Browse
Browse