Community Forums › Forums › Archived Forums › General Discussion › How to create a Custom Post Type and template
Tagged: custom post type acf repeater
- This topic has 1 reply, 2 voices, and was last updated 8 years, 1 month ago by Brad West.
-
AuthorPosts
-
February 17, 2016 at 1:56 pm #179263digi57Member
I'm still trying to wrap my head around templates and custom post types in general. I've been going through tutorial after tutorial and I can't figure out how to do what I'm trying to do in Genesis.
Basically, I am trying to make a Custom Post Type for a client to post bi-weekly menus for a meal delivery business. I have Advanced Custom Fields set up with Repeater fields. While setting it up, I just called the ACF fields with php INSIDE the post using a plugin that enables me to use php in the post.
This is the code I use to call the fields:
<article class="menu-week">
<div class="week-header">
<h2><?php the_title(); ?></h2>
<p><?php the_field('days'); ?></p>
</div>
<section class ="breakfast-bowls">
<h4>Super Food Breakfast Bowls w/ OatPro3</h4>
<p class="calories">417 Calories</p>
<?php
if( have_rows('superfoods_breakfast_bowls_w/oatpro3') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('superfoods_breakfast_bowls_w/oatpro3') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('breakfast_bowl_name'); ?>
<li class="item-description"><?php the_sub_field('breakfast_bowl_description'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end breakfast-bowls --><section class ="muffins">
<h4>Super Food Muffins w/ OatPro3</h4>
<p class="calories">400 Calories</p>
<?php
if( have_rows('superfoods_muffins_w/oatpro3') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('superfoods_muffins_w/oatpro3') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('muffin_name'); ?>
<li class="item-description"><?php the_sub_field('muffin_description'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end muffins --><section class ="eggs">
<h4>Egg Breakfasts</h4>
<p class="calories">400 Calories</p>
<?php
if( have_rows('egg_breakfast') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('egg_breakfast') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('egg_breakfast_name'); ?>
<li class="item-description"><?php the_sub_field('egg_breakfast_description'); ?>
<li class="item-description">Optional Added Protein: <?php the_sub_field('egg_breakfast_protein'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end eggs --><section class ="protein-balls">
<h4>Protein Balls</h4>
<p class="calories">200 Calories Each</p>
<?php
if( have_rows('protein_balls') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('protein_balls') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('protein_ball_name'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end protein-balls --><section class ="midday">
<h4>Midday Protein Pick-Me-Ups</h4>
<p class="calories">300 Calories</p>
<?php
if( have_rows('midday_protein') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('midday_protein') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('midday_name'); ?>
<li class="item-description"><?php the_sub_field('midday_description'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end midday --><section class ="shakes-juice">
<h4>Shakes And Green Juices</h4>
<p class="calories">300 Calories</p>
<?php
if( have_rows('shakes_&_green_juices') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('shakes_&_green_juices') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('shake/juice_name'); ?>
<li class="item-description"><?php the_sub_field('shake/juice_description'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end shakes-juice --><section class ="lunches-dinners">
<h4>Lunches & Dinners</h4>
<p class="calories">400-600 Calories</p>
<?php
if( have_rows('lunches/dinners') ): ?>
<?php $field = get_field($field_name); ?>-
<?php while( have_rows('lunches/dinners') ): the_row(); ?>
<li class="item-name"><?php the_sub_field('meal_name'); ?>
<li class="item-description"><?php the_sub_field('meal_description'); ?>
<?php endwhile; ?><?php endif; ?>
</section><!-- end shakes-juice -->
</article><!-- end menu-week -->This code works great and called the fields exactly how I want. My goal is to set it so so when the client goes to post a new custom post, All he sees is the ACF fields that he needs to fill, and when he posts it, it shows up on the blog page.
March 4, 2016 at 2:49 am #180625Brad WestMemberIf I understand you correctly you're just trying to allow the fields to be edited on the home page inside the WordPress dashboard. Open your field groups inside Custom Fields, there is an area below your fields called Location (Show this field group if). You can use that to show that field group for a certain template, page or post type.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.