Create Programs custom post type and make relation between program and event

 First we create custom post type for programs so go to mu-plugins and open php file for custom post.

In university_post_types() copy event post type code and repeat this code inside function and rename the things.

In program custom post type code remove excerpt from supports and add icon dashicons-awards

After that go to dashboard create Math program with dummy text and publish and also go permalinks and update

Now this program single post use single.php but i want create dedicated page for this like single-program.php


Now copy code from single-event.php and paste in single-program.php

Now change metabox like below code

  <a class="metabox__blog-home-link" href="<?php echo get_post_type_archive_link('program'); ?>">
        <i class="fa fa-home" aria-hidden="true"></i> Programs Home
      </a>

and save

Now to display program archive we have to create archive-program.php page

and copy archive-event.php code and paste in archive-program.php page

And change title All Program also make empty while loop we will change design for program display.

add below code -> 

<ul class="link-list min-list">
    <?php
    while(have_posts()) {
        the_post(); ?>
    <li><a href="<?php the_permalink();?>"><?php the_title();  ?></a></li>

    <?php }
  echo paginate_links();
  ?>
  </ul>

and save now i want display program alphabet order so we have to write code in functions.php

Now go to university_adjust_queries() function and add below code 

  if(!is_admin() && is_post_type_archive('program') && $query->is_main_query()) {
    $query->set('orderby', 'title');
    $query->set('order', 'ASC');
    $query->set('posts_per_page', -1); //show all programs
  }

and save

Now make relation between Program and Events.

Go to Custom fields and create new give title Related Program and label Related Program(s)

field name related_programs field type Relationship

Filter by post type - program and Filters only Search

Location rules post type -> event

Now make save changes

Now edit any events you will see custom fields for Programs and add program and save change.


Comments

Popular posts from this blog

Basics Of PHP

Creating App.js for Node Application

WordPress Full Guide For Developer