create a brand new post type name Program
Few Examples of Program Post like
Maths
Biology ---Cats
English------>PoetryDay
Create a Relationship between Certain Program with Certain Events
in a Homepage we made Custom Post PoetryDay and we associate English Program
Sci Cats Events realte with the Biology Program
Once we Established a relationships Between Once Post with another
then its piece of Cake to Create Html Links
visitoras can hop back and forth all of the related between the Content
Before Creating Relation First we Will
Create Brand New Custom Post type Program
in ur text instead of Theme Folder Go to mu folder
their we create php file
you will see register our Event Post Type
so it very easy for us to now create anothe Custom Post type
e can literally copy and paste this code except function header line
select from register from very beginning to ending semi colon
copy drop new line
php comment
//program type
paste ur code after two close braces semicolon and before last curly braces
type this line ans change some key Values
register_post_type(event
//Program Post Type
register_post_type('program', array(
'rewrite' => array('slug' => 'programs'),
'has_archive' => true,
'public' => true,
'labels' => array(
'name' => 'Programs',
'add_new_item' => 'Add New Program',
'edit_item' => 'Edit Event',
'all_items' => 'All Programs',
'singular_name' => 'Program'
),
'menu_icon' => 'dashicons-awards',
'supports' => array('title', 'editor', /*'excerpt',*/ /*'custom-fields'*/),
));
Create Dammy 3 or 4 Sample Program
Math English Biology
clck permalonk to preview the newly create program posts
we didnt see any Content and if you see on the tab its Apge not Found
The Problem Here is We Just Register a New Post type in our mu folder
thats uses new url or permalink structure
so all we need to is to fix is tell the wordpress to
updates is permalink
in the admin so go to settings click Permalink and simply click Save Changes
and it will force wordpress to regenerate all of its permalink for urls
and as soon as we did that refresh the biology posts
we have a screen with English post and its main content view
at the moment this post is using Generic Blog Post Template
because we can see the link here back to the BLog Home
and the screen is powerd by single.php
but we will created ad edicated Template File
just for Individual Program Post
Go to Theme Folder and Createa FIle named single-program.php
copy all the code from single-event.php as a guide or starting point to this newly
created some File and do some tweak
customize meta div
however
our all program isusing genric listing Style
this style best soothed for Blog Post but
we dont care in the progra who the post creator and its data
and so as we know that this all program url is powere by genric archive.php
so we will create a new file is only responsible for program
archive
relationship
event post have custom field with relate program option
and in front end its show related program biology and if you tick that it will tske
you biology program
and in each section says upcoming biology events
the key here is we need to create custom field
thats help you to pick which post you have to relate with the current post u
areeditibg
click create custom fields icon in the sidebar
create a new field named Related Program
click add field
named it
s for add more programs
Related Program(s)
required no
field tye relationship
post type option choose program
set everthing else default
scroll down further to location box whic is super important
show this field group if
post type = event
click publiush
how we use custom field value of our front end of our websites
Displaying Relation ship on to the FrontEnd Of Our Webistes
for Example if we go to our Homepage we see The SCi of Cats event post
an di f click on it and then i used edit event button at the Top Menu Bar
you will new Custom Field Option Relation Program Option appaear
you make raltion with Biology Program
so our next task is how do we display our Relation ship on Front End
so if we go back to Sci of Cats Detailed Screen
how could we out put with the Content Down here
reads Related Programs
then have a link to Biology Program
go to the theme folder
singleevent.php file
go to the bottom insert this code within the DIv of Generic Content
drop down the php tag
make a new use a dollar sighn variable named relatedPrograms
equal to result get field function
then give custom field name we want to retreive
which u get from the field group having field which have a name
saving avalue of the field in the variable
now what object we decide to resides inside the variable
string array
down on the next line
//print_r($relatedPrograms): give output the data type
array all sortof values contains
loop through the array do something once for each item
<?php
$relatedPrograms = get_field('related_programs');
if ($relatedPrograms) {
echo '<hr class="section-break">';
echo '<h2 class="headline headline--medium">Related Program(s)</h2>';
echo '<ul class="link-list min-list">';
foreach($relatedPrograms as $program) { ?>
<li><a href="<?php echo get_the_permalink($program); ?>"><?php echo
get_the_title($program); ?></a></li>
<?php }
echo '</ul>';
}
?>