Advanced Custom Fields – Create A Custom Post Type For Movies

Updated June 10th, 2020
Updated June 10th, 2020
Share this post:
Share on facebook
Share on twitter
Share on reddit
Share on linkedin
Share on pinterest
Share on pocket
Share on email
Share on print

Before you can use the advanced custom fields plugin you need to create a custom post type.

To create a Custom Post Type you have two options, one is to use a plugin to create custom post types and other is to do it manually.

Once you have a custom post type created you can go ahead and start creating custom fields using the Advanced Custom Fields tutorial.

The code below will make a lot more sense if you following along with the video tutorial.

Movies Custom Post Type Code From Video Tutorial

<?php get_header(); ?>


<?php 

// Declare needed variables

// Get The featured image
if( has_post_thumbnail() ){
	$featuredimg = get_the_post_thumbnail_url();
} else {
	$featuredimg = 'PATH-TO-DEFAULT-IMAGE';
}

// Get the Genre field
if( get_field('genre') ){
	$genres = get_field('genre');
}

// Get Duration field
if( get_field('duration') ){
	$duration = get_field('duration');
}

// Get Rating field
if( get_field('rating') ){
	$rating = get_field('rating');
}

// Get Movie Image field
if( get_field('movie_image') ){
	$movie_image = get_field('movie_image');
}

// Get Release date field
if( get_field('release_date') ){
	$release_date = get_field('release_date', false, false);
	$releaseDate = new DateTime($release_date);
}
// Get country field
if( get_field('country') ){
	$country = get_field('country');
}
// Get language field
if( get_field('language') ){
	$language = get_field('language');
}
// Get budget field
if( get_field('budget') ){
	$number = get_field('budget');
	// let's print the international format for the en_US locale
	setlocale(LC_MONETARY, 'en_US.UTF-8');
	$budget = money_format('%.2n ', $number);
}
// Get opening_weekend field
if( get_field('opening_weekend') ){
	$number = get_field('opening_weekend');
	// let's print the international format for the en_US locale
	setlocale(LC_MONETARY, 'en_US.UTF-8');
	$opening_weekend = money_format('%.2n ', $number);
}
// Get movie storyline field
if( get_field('movie_storyline') ){
	$movie_storyline = get_field('movie_storyline');
}
?><
<div id="main" class="main-content clearfix"><?php while ( have_posts() ) : the_post(); ?>
<div class="banner-section clearfix" style="background-image: url(<?php echo $featuredimg; ?>
<div class="container">
<div class="col column1 clearfix">&nbsp;</div>
<div class="col column2 clearfix">
<h1 class="post-title"><?php echo get_the_title(); ?></h1>
<div class="post-details">
<p class="genre"><?php
		foreach( $genres as $genre ){
		echo '<span>' . $genre . ''; }?> <span class="duration"> | <?php echo $duration . ' mins'; ?></span></p>
<p class="rating">Rating: <?php echo $rating; ?></p>
</div>
</div>
</div>
</div>
<div class="body-section clearfix">
<div class="container">
<div class="col column1 clearfix">
<div class="movie-image" style="background-image: url(<?php echo $movie_image; ?></div>
<h2>Movie Info</h2>
<div class="movieinfo">
<p><strong>Release Date:</strong> <?php echo $releaseDate->format('j F Y'); ?> (<?php echo $country; ?>)</p>
<p class="genre2"><strong>Genres:</strong> <?php
								foreach( $genres as $genre ){
									echo '<span>' . $genre . ''; } ?></p>
<p><strong>Country:</strong> <?php echo $country; ?></p>
<p><strong>Language:</strong> <?php echo $language; ?></p>
<p><strong>Budget:</strong> <?php echo $budget; ?> (estimated)</p>
<p><strong>Opening Weekend:</strong> <?php echo $opening_weekend; ?></p>
</div>
</div>
<div class="col column2 clearfix">
<div class="storyline">
<h2>Movie Storyline</h2>
<p><?php echo $movie_storyline; ?></p>
</div>
<div class="trailer">
<h2>Trailer</h2>
<div class="video-frames"><?php // Get Trailer fields
		if( have_rows('trailers') ){
			while( have_rows('trailers') ): the_row(); 
			// Subfields
				if( get_sub_field('trailer_url') ){
	 				$trailer_url = get_sub_field('trailer_url');
	 				echo '<div class="embed-container"--><iframe src="'. $trailer_url . '" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe></div>'; } endwhile; ?></div>
</div>
<div class="cast">
<h2>Cast</h2>
<div class="cast-list clearfix"><?php // Get cast fields
		if( have_rows('cast_members') ){
		  while( have_rows('cast_members') ): the_row(); 
		   // Subfields
			if( get_sub_field('cast_member_image') ){$cast_member_image = get_sub_field('cast_member_image');
										}
			if( get_sub_field('cast_member_real_name') ){
	 										$cast_member_real_name = get_sub_field('cast_member_real_name');
										}
			if( get_sub_field('cast_member_character_name') ){
	 										$cast_member_character_name = get_sub_field('cast_member_character_name');
										}
				    echo '<div class="casts">'; 
                                    echo '<img src="' . $cast_member_image . '" alt="">'; 
                                    echo '<h3 class="cast-real-name">' . $cast_member_real_name . '</h3>'; 
                                    echo '<p class="cast-char-name">as <strong>' . $cast_member_character_name . '</strong></p>';
                                    echo '</div>'; 
                                    endwhile; ?></div>
</div>
</div>
</div>
<?php endwhile; ?> <?php get_footer(); ?>

Movies CSS Code From Video Tutorial

/* === Single Movie Page === */
h1, 
h2, 
h3, 
h4, 
h5, 
h6{
    font-family: Helvetica, sans-serif;
}
body{
	font-family: Arial, Helvetica, sans-serif;
}
#main .col {
    float: left;
}
#main .column1 {
    width: 28%;
    padding-right: 30px;
	min-height: 1px;
}
#main .column2 {
    width: 72%;
}
.banner-section {
    background-repeat: no-repeat;
    background-size: cover;
    background-position: top;
    position: relative;
    padding-top: 440px;
    padding-bottom: 55px;
}
h1.post-title {
    color: #ffffff;
    font-size: 34px;
    padding-bottom: 20px;
}
p.genre, 
p.rating {
    color: #ffffff;
    font-size: 16px;
}
p.genre &gt; span:after,
p.genre2 &gt; span:after{
    content: ', ';
}
p.genre2 &gt; span:last-child:after,
p.genre &gt; span:last-child:after, 
p.genre &gt; span:nth-last-child(2):after {
    display: none;
}
.body-section {
    padding: 45px 0;
}
.movie-image {
    min-height: 360px;
    width: 100%;
    max-width: 220px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    margin-top: -330px;
    margin-bottom: 30px;
    -webkit-box-shadow: 3px 4px 5px rgba(0,0,0,.75);
    -moz-box-shadow: 3px 4px 5px rgba(0,0,0,.75);
    box-shadow: 3px 4px 5px rgba(0,0,0,.75);
}
.body-section h2 {
    font-size: 25px;
    color: #000000;
    padding-bottom: 30px;
}
.movieinfo p {
    font-size: 16px;
    color: #000000;
}
.storyline p {
    font-size: 16px;
    color: #000000;
    line-height: 1.4em;
    margin-bottom: 30px;
}
.trailer {
    margin-bottom: 30px;
}
.cast-list .casts {
    float: left;
    width: 20%;
    text-align: center;
    padding-right: 20px;
}
.cast-list .casts h3.cast-real-name {
    font-family: Arial,Helvetica,sans-serif;
    font-size: 20px;
    color: #0677ea;
    padding-top: 10px;
}
.cast-list .casts p.cast-char-name {
    color: #000000;
    font-size: 16px;
}
.embed-container { 
	position: relative; 
	padding-bottom: 56.25%;
	height: 0;
	overflow: hidden;
	max-width: 100%;
	height: auto;
	margin-bottom: 30px;
} 
.embed-container iframe,
.embed-container object,
.embed-container embed { 
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}

/* === Responsive CSS === */
@media screen and (max-width: 1024px) {
.cast-list .casts {
    width: 33.333%;
    margin-bottom: 30px;
}
}
@media screen and (max-width: 980px) {
#main .col {
    float: none;
    width: 100%;
    padding-right: 0 !important;
}
.movie-image {
    margin-top: 0;
    margin: 0 auto 30px;
}
.banner-section {
    padding-top: 200px;
    padding-bottom: 55px;
}
#main .col {
    text-align: center;
}
.movieinfo {
    margin-bottom: 30px;
}
}
@media screen and (max-width: 568px) {
.cast-list .casts {
    width: 50%;
}
}
@media screen and (max-width: 414px) {
h1.post-title {
    font-size: 30px;
}
.cast-list .casts {
    width: 100%;
    padding-right: 0;
}
}

Lists For Advanced Custom Fields

Genres

Action : Action
Adventure : Adventure
Comedy : Comedy
Documentary : Documentary
Drama : Drama
Epics/Historical : Epics/Historical
Horror : Horror
Musicals : Musicals
Sci-fi : Sci-fi
War : War
Westerns : Westerns

Countries

Afghanistan : Afghanistan
Albania : Albania
Algeria : Algeria
Andorra : Andorra
Angola : Angola
Antigua and Barbuda : Antigua and Barbuda
Argentina : Argentina
Armenia : Armenia
Aruba : Aruba
Australia : Australia
Austria : Austria
Azerbaijan : Azerbaijan
Bahamas, The : Bahamas, The
Bahrain : Bahrain
Bangladesh : Bangladesh
Barbados : Barbados
Belarus : Belarus
Belgium : Belgium
Belize : Belize
Benin : Benin
Bhutan : Bhutan
Bolivia : Bolivia
Bosnia and Herzegovina : Bosnia and Herzegovina
Botswana : Botswana
Brazil : Brazil
Brunei : Brunei
Bulgaria : Bulgaria
Burkina Faso : Burkina Faso
Burma : Burma
Burundi : Burundi
Cambodia : Cambodia
Cameroon : Cameroon
Canada : Canada
Cabo Verde : Cabo Verde
Central African Republic : Central African Republic
Chad : Chad
Chile : Chile
China : China
Colombia : Colombia
Comoros : Comoros
Congo, Democratic Republic of the : Congo, Democratic Republic of the
Congo, Republic of the : Congo, Republic of the
Costa Rica : Costa Rica
Cote d'Ivoire : Cote d'Ivoire
Croatia : Croatia
Cuba : Cuba
Curacao : Curacao
Cyprus : Cyprus
Czechia : Czechia
Denmark : Denmark
Djibouti : Djibouti
Dominica : Dominica
Dominican Republic : Dominican Republic
East Timor (see Timor-Leste) : East Timor (see Timor-Leste)
Ecuador : Ecuador
Egypt : Egypt
El Salvador : El Salvador
Equatorial Guinea : Equatorial Guinea
Eritrea : Eritrea
Estonia : Estonia
Ethiopia : Ethiopia
Fiji : Fiji
Finland : Finland
France : France
Gabon : Gabon
Gambia, The : Gambia, The
Georgia : Georgia
Germany : Germany
Ghana : Ghana
Greece : Greece
Grenada : Grenada
Guatemala : Guatemala
Guinea : Guinea
Guinea-Bissau : Guinea-Bissau
Guyana : Guyana
Haiti : Haiti
Holy See : Holy See
Honduras : Honduras
Hong Kong : Hong Kong
Hungary : Hungary
Iceland : Iceland
India : India
Indonesia : Indonesia
Iran : Iran
Iraq : Iraq
Ireland : Ireland
Israel : Israel
Italy : Italy
Jamaica : Jamaica
Japan : Japan
Jordan : Jordan
Kazakhstan : Kazakhstan
Kenya : Kenya
Kiribati : Kiribati
Korea, North : Korea, North
Korea, South : Korea, South
Kosovo : Kosovo
Kuwait : Kuwait
Kyrgyzstan : Kyrgyzstan
Laos : Laos
Latvia : Latvia
Lebanon : Lebanon
Lesotho : Lesotho
Liberia : Liberia
Libya : Libya
Liechtenstein : Liechtenstein
Lithuania : Lithuania
Luxembourg : Luxembourg
Macau : Macau
Macedonia : Macedonia
Madagascar : Madagascar
Malawi : Malawi
Malaysia : Malaysia
Maldives : Maldives
Mali : Mali
Malta : Malta
Marshall Islands : Marshall Islands
Mauritania : Mauritania
Mauritius : Mauritius
Mexico : Mexico
Micronesia : Micronesia
Moldova : Moldova
Monaco : Monaco
Mongolia : Mongolia
Montenegro : Montenegro
Morocco : Morocco
Mozambique : Mozambique
Namibia : Namibia
Nauru : Nauru
Nepal : Nepal
Netherlands : Netherlands
New Zealand : New Zealand
Nicaragua : Nicaragua
Niger : Niger
Nigeria : Nigeria
North Korea : North Korea
Norway : Norway
Oman : Oman
Pakistan : Pakistan
Palau : Palau
Palestinian Territories : Palestinian Territories
Panama : Panama
Papua New Guinea : Papua New Guinea
Paraguay : Paraguay
Peru : Peru
Philippines : Philippines
Poland : Poland
Portugal : Portugal
Qatar : Qatar
Romania : Romania
Russia : Russia
Rwanda : Rwanda
Saint Kitts and Nevis : Saint Kitts and Nevis
Saint Lucia : Saint Lucia
Saint Vincent and the Grenadines : Saint Vincent and the Grenadines
Samoa : Samoa
San Marino : San Marino
Sao Tome and Principe : Sao Tome and Principe
Saudi Arabia : Saudi Arabia
Senegal : Senegal
Serbia : Serbia
Seychelles : Seychelles
Sierra Leone : Sierra Leone
Singapore : Singapore
Sint Maarten : Sint Maarten
Slovakia : Slovakia
Slovenia : Slovenia
Solomon Islands : Solomon Islands
Somalia : Somalia
South Africa : South Africa
South Korea : South Korea
South Sudan : South Sudan
Spain : Spain
Sri Lanka : Sri Lanka
Sudan : Sudan
Suriname : Suriname
Swaziland : Swaziland
Sweden : Sweden
Switzerland : Switzerland
Syria : Syria
Taiwan : Taiwan
Tajikistan : Tajikistan
Tanzania : Tanzania
Thailand : Thailand
Timor-Leste : Timor-Leste
Togo : Togo
Tonga : Tonga
Trinidad and Tobago : Trinidad and Tobago
Tunisia : Tunisia
Turkey : Turkey
Turkmenistan : Turkmenistan
Tuvalu : Tuvalu
Uganda : Uganda
Ukraine : Ukraine
United Arab Emirates : United Arab Emirates
United Kingdom : United Kingdom
Uruguay : Uruguay
USA : USA
Uzbekistan : Uzbekistan
Vanuatu : Vanuatu
Venezuela : Venezuela
Vietnam : Vietnam
Yemen : Yemen
Zambia : Zambia
Zimbabwe : Zimbabwe

Languages

English : English
Abkhaz : Abkhaz
Adyghe : Adyghe
Afrikaans : Afrikaans
Akan : Akan
Albanian : Albanian
American Sign Language : American Sign Language
Amharic : Amharic
Arabic : Arabic
Aragonese : Aragonese
Aramaic : Aramaic
Armenian : Armenian
Aymara : Aymara
Balinese : Balinese
Basque : Basque
Betawi : Betawi
Bosnian : Bosnian
Breton : Breton
Bulgarian : Bulgarian
Cantonese : Cantonese
Catalan : Catalan
Cherokee : Cherokee
Chickasaw : Chickasaw
Chinese : Chinese
Coptic : Coptic
Cornish : Cornish
Corsican : Corsican
Crimean Tatar : Crimean Tatar
Croatian : Croatian
Czech : Czech
Danish : Danish
Dutch : Dutch
Dawro : Dawro
Esperanto : Esperanto
Estonian : Estonian
Ewe : Ewe
Fiji Hindi : Fiji Hindi
Filipino : Filipino
Finnish : Finnish
French : French
Galician : Galician
Georgian : Georgian
German : German
Greek, Modern : Greek, Modern
Ancient Greek : Ancient Greek
Greenlandic : Greenlandic
Haitian Creole : Haitian Creole
Hawaiian : Hawaiian
Hebrew : Hebrew
Hindi : Hindi
Hungarian : Hungarian
Icelandic : Icelandic
Indonesian : Indonesian
Inuktitut : Inuktitut
Interlingua : Interlingua
Irish : Irish
Italian : Italian
Japanese : Japanese
Javanese : Javanese
Kabardian : Kabardian
Kalasha : Kalasha
Kannada : Kannada
Kashubian : Kashubian
Khmer : Khmer
Kinyarwanda : Kinyarwanda
Korean : Korean
Kurdish/Kurdî : Kurdish/Kurdî
Ladin : Ladin
Latgalian : Latgalian
Latin : Latin
Lingala : Lingala
Livonian : Livonian
Lojban : Lojban
Lower Sorbian : Lower Sorbian
Low German : Low German
Macedonian : Macedonian
Malay : Malay
Malayalam : Malayalam
Mandarin : Mandarin
Manx : Manx
Maori : Maori
Mauritian Creole : Mauritian Creole
Middle Low German : Middle Low German
Min Nan : Min Nan
Mongolian : Mongolian
Norwegian : Norwegian
Old Armenian : Old Armenian
Old English : Old English
Old French : Old French
Old Javanese : Old Javanese
Old Norse : Old Norse
Old Prussian : Old Prussian
Oriya : Oriya
Pangasinan : Pangasinan
Papiamentu : Papiamentu
Pashto : Pashto
Persian : Persian
Pitjantjatjara : Pitjantjatjara
Polish : Polish
Portuguese : Portuguese
Proto-Slavic : Proto-Slavic
Quenya : Quenya
Rapa Nui : Rapa Nui
Romanian : Romanian
Russian : Russian
Sanskrit : Sanskrit
Scots : Scots
Scottish Gaelic : Scottish Gaelic
Serbian : Serbian
Serbo-Croatian : Serbo-Croatian
Slovak : Slovak
Slovene : Slovene
Spanish : Spanish
Sinhalese : Sinhalese
Swahili : Swahili
Swedish : Swedish
Tagalog : Tagalog
Tajik : Tajik
Tamil : Tamil
Tarantino : Tarantino
Telugu : Telugu
Thai : Thai
Tok Pisin : Tok Pisin
Turkish : Turkish
Twi : Twi
Ukrainian : Ukrainian
Upper Sorbian : Upper Sorbian
Urdu : Urdu
Uzbek : Uzbek
Venetian : Venetian
Vietnamese : Vietnamese
Vilamovian : Vilamovian
Volapük : Volapük
Võro : Võro
Welsh : Welsh
Xhosa : Xhosa
Yiddish : Yiddish
Share this post:
Share on facebook
Share on twitter
Share on reddit
Share on linkedin
Share on pinterest
Share on pocket
Share on email
Share on print
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email

Responses

Your email address will not be published.

  1. question: don’t you have to put the custom fields also in the function.php?

    1. Hi Nordie,

      Good question and the answer is you don’t. You just need to create the custom fields using ACF and then put the custom fields PHP output in the template file. Everything you need to recreate what I show in the video is in this post.

      Thanks for the comment and I hope that helps.

  2. Hi Bjorn,
    Thanks it seems an awesome course. I will complete your course and the project. Actually I had purchased few WP courses on http://www.udemy.com however I was stuck. I could not print the custom sized images using in ACF. I could print same image using the filename from get_field function. This code doesn’t work $id=get_field(‘image’); $image= wp_get_attachment_image($id, ‘size’); echo $image[0]; This code dosn’t work either $image=wp_attachment_image_src($id, ‘size’); echo $image; I do not get an array when i use var_dump($image); // functions.php code function theme_setup { add_image_size(‘size’, 470, 200, true); } Anyway, I hope your course covers how to use custom image sizes in ACF’s post. Thank you 🙂

    1. Hi Vaibhav,

      With images in ACF it’s important to make sure you choose the right output: object, url or id. And then have the corresponding PHP that can work with the output.

      In this tutorial I only cover the URL output.

      I hope it helps and thanks for stopping by!

    1. Genres are probably the best way to differentiate between comedy and horror movies. Did you see the part of the tutorial where I define genres? That’s probably what you want to do. It’s somewhere in the middle of the video tutorial.

  3. Hey Bjorn,
    I’m having trouble figuring out how to create a hard link in my custom fields.
    I set up my custom field type as text and added the prepend http:// but ‘m not sure what the php output should be in order for it to show up as a clickable link on the front end. Can you help me please? Thanks!

    1. Hi Karen,

      For this example, I’m going to use the variable $link. The prepend of http:// in the backend does not add http:// to the variable so we have to add it in when we output using PHP. Here’s how you would create a link:

      “>Link anchor text

      That will create a clickable link with the text “Link anchor text”. If you want to create a clickable image you would do it like this:

      “>

      In the example above, “path/to/the/image.jpg” is the URL to the image.

      I hope that helps and thanks for stopping by!

  4. I’ve followed this tutorial to a T and I still cant get the movie trailer to display. All the ‘movie_trailers’ and the ‘trailer_link’ are correct. On the front end it’s just showing white space. Everything else is right except maybe the CSS needs to be adjusted. I’m using Astra Theme.

WPLearningLab

Warning: Use of undefined constant WPBF_CHILD_THEME_URI - assumed 'WPBF_CHILD_THEME_URI' (this will throw an Error in a future version of PHP) in /home/customer/www/wplearninglab.com/public_html/wp-content/themes/buddyboss-theme-child/functions.php on line 108

Warning: Use of undefined constant WPBF_CHILD_VERSION - assumed 'WPBF_CHILD_VERSION' (this will throw an Error in a future version of PHP) in /home/customer/www/wplearninglab.com/public_html/wp-content/themes/buddyboss-theme-child/functions.php on line 108