Took some time off from this to let the dust settle on the Gutenberg ecosystem. Got back into it recently and am having pretty good results with this approach. Just a warning, it’s mostly Javascript-based. I strongly suggest you grab @wordpress/scripts (https://github.com/WordPress/gutenberg/blob/master/packages/scripts/README.md) so you can write your React code in es2015.
First, I removed all of the extra “settings” field groups I was cloning, leaving each block field group with ONLY the specific fields needed to get content into the view. So instead of like: Heading, Text, Clone of Spacing settings field group, Clone of Background settings field group, it’s only Heading and Text.
Then we get into the JS. First we add a filter for the block setings that will let us add attributes for all of the settings we want to customize: backgroundColor, paddingTop, whatever.
import { assign } from 'lodash';
const { addFilter } = wp.hooks;
const customBlockAttributes = {
backgroundColor: {
type: 'string'
},
paddingTop: {
type: 'string'
},
whatever: {
type: 'string'
},
};
addFilter('blocks.registerBlockType', 'my_domain', (settings, name) => {
/**
* If this is an acf block, add our custom attributes!
if (name.match(/^acf/)) {
settings.attributes = assign(settings.attributes, customBlockAttributes);
}
return settings;
});
Then we add another filter on editor.BlockEdit. If it’s an ACF block, we return a Fragment that wraps up the BlockEdit PLUS an InspectorControls component that has whatever React stuff we want!
addFilter('editor.BlockEdit', 'my_domain', createHigherOrderComponent(BlockEdit => {
return props => {
if (!props.name.match(/^acf/)) {
return <BlockEdit {...props} />;
} else {
return (
<Fragment>
<BlockEdit {...props} />
<InspectorControls>
{/* add react components here! */}
</InspectorControls>
</Fragment>
);
}
};
}, 'withCustomBlockSettings'));
Took some time off from this to let the dust settle on the Gutenberg ecosystem. Got back into it recently and am having pretty good results with this approach. Just a warning, it’s mostly Javascript-based. I strongly suggest you grab @wordpress/scripts (https://github.com/WordPress/gutenberg/blob/master/packages/scripts/README.md) so you can write your React code in es2015.
First, I removed all of the extra “settings” field groups I was cloning, leaving each block field group with ONLY the specific fields needed to get content into the view. So instead of like: Heading, Text, Clone of Spacing settings field group, Clone of Background settings field group, it’s only Heading and Text.
Then we get into the JS. First we add a filter for the block setings that will let us add attributes for all of the settings we want to customize: backgroundColor, paddingTop, whatever.
import { assign } from 'lodash';
const { addFilter } = wp.hooks;
const customBlockAttributes = {
backgroundColor: {
type: 'string'
},
paddingTop: {
type: 'string'
},
whatever: {
type: 'string'
},
};
addFilter('blocks.registerBlockType', 'my_domain', (settings, name) => {
/**
* If this is an acf block, add our custom attributes!
if (name.match(/^acf/)) {
settings.attributes = assign(settings.attributes, customBlockAttributes);
}
return settings;
});
Then we add another filter on editor.BlockEdit. If it’s an ACF block, we return a Fragment that wraps up the BlockEdit PLUS an InspectorControls component that has whatever React stuff we want!
addFilter('editor.BlockEdit', 'my_domain', createHigherOrderComponent(BlockEdit => {
return props => {
if (!props.name.match(/^acf/)) {
return <BlockEdit {...props} />;
} else {
return (
<Fragment>
<BlockEdit {...props} />
<InspectorControls>
{/* add react components here! */}
</InspectorControls>
</Fragment>
);
}
};
}, 'withCustomBlockSettings'));
This has been solved. The code is below.
<?php
/**
* The template for displaying all pages
*
* Template Name: Feature Comparison
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Merchant_Services
*/
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php get_template_part( 'template-parts/content','hero' ); ?>
<div class="comparison-box-wrapping">
<?php $loop = new WP_Query( array(
'post_type' => 'comparison_tables',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => '5') );
?>
<?php while( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="comparison-block">
<div class="recommend-header"><h2 class="green-medium"><?php the_title(); ?></h2></div>
<table>
<thead>
<tr>
<th> </th>
<?php $legends = get_field('legend');
if($legends){
foreach($legends as $legend){
$company_attributes = $legend['company_attributes'];
foreach ($company_attributes as $company_attribute) {
$companies = $company_attribute['company'];
$count++;
//limit the count to only get the logos from the first legend
if( has_post_thumbnail($companies->ID) && $count < 6) {
echo "<th>";
$thumb = get_the_post_thumbnail($companies->ID, 'full');
echo $thumb;
echo "</th>";
};
}
}
} ; ?>
</tr>
</thead>
<tbody>
<?php if ( have_rows( 'legend' ) ) : ?>
<?php while( have_rows('legend') ): the_row();
$legend_title = get_sub_field('legend_title');
?>
<tr>
<td><p><?php echo $legend_title; ?></p></td>
<?php while ( have_rows( 'company_attributes' ) ) : the_row();
$attribute = get_sub_field('attribute');
?>
<td><?php echo $attribute; ?></td>
<?php endwhile; ?>
</tr>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
</div> <!-- comparison-block END -->
<?php endwhile; ?>
</div> <!-- comparison-box-wrapping END -->
<?php get_template_part( 'template-parts/content','disclosure-dark' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
Here is the full template file with both layouts. It might not be the prettiest WordPress code, but I’m more of a static html guy haha:
<?php
/*
Template Name: Property Page
*/
get_header();
$cf_property_title = get_field('cf_property_title');
$cf_property_address = get_field('cf_property_address');
$main_banner_image = get_field('main_banner_image');
$mls_number = get_field('mls_number');
$listing_price = get_field('listing_price');
$bedrooms = get_field('bedrooms');
$bathrooms = get_field('bathrooms');
$square_feet = get_field('square_feet');
$garage = get_field('garage');
$property_description = get_field('property_description');
$map_short_code = get_field('map_short_code');
$matterport_iframe = get_field('matterport_iframe');
$floor_plan = get_field('floor_plan');
$area_title = get_field('area_title');
$area_description = get_field('area_description');
$area_image = get_field('area_image');
if ( get_query_var( 'subpage' ) ) {
// if ?subpage=flyer is used, load the content for flyer-1
?>
<?php the_post(); ?>
<!-- ==================== -->
<!-- flyer section -->
<!-- ==================== -->
<?php
//contact info
$first_name = get_the_author_meta('first_name');
$last_name = get_the_author_meta('last_name');
$id = get_the_author_meta('ID');
$author_id = "user_".$id;
$agency = get_field('agency', $author_id );
$agency_logo = get_field('agency_logo', $author_id );
$website_url = get_field('website_url', $author_id);
$email_address = get_field('email_address', $author_id);
$phone_main = get_field('phone_main', $author_id);
$cell_phone = get_field('cell_phone', $author_id);
$fax_number = get_field('fax_number', $author_id);
$street_address = get_field('street_address', $author_id);
$address_line_2 = get_field('address_line_2', $author_id);
$city = get_field('city', $author_id);
$zipcode = get_field('zipcode', $author_id);
$profile_pic = get_field('profile_pic', $author_id);
$email_address = get_field('email_address', $author_id);
?>
<section class="header">
<div class="container">
<div class="row">
<div class="col-xs-6 text-left">
<h1 class="company"><?php echo $agency;?></h1>
<h2 class="realtor"><?php echo $first_name." ".$last_name; ?></h2>
</div><!-- close col -->
<div class="col-xs-6 text-right">
<h1 class="price"><?php echo $listing_price;?></h1>
<h2 class="address"><?php echo $cf_property_address?></h2>
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
<section class="banner-image">
<div class="container">
<div class="row">
<div class="col-xs-12">
<img class="img-responsive" src="<?php echo $main_banner_image ?>'">
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
<section class="main-content">
<div class="container">
<div class="row">
<div class="col-xs-3 left-column">
<img class="img-responsive logo" src="<?php echo $agency_logo; ?>">
<div class="contact-info">
<ul class="list-unstyled">
<li class="name"><?php echo $first_name." ".$last_name;?> </li>
<li>Phone: <?php echo $phone_main;?></li>
<li>Email: <?php echo $phone_main;?></li>
<li>Website: <?php echo $website_url;?></li>
</ul>
</div><!-- close contact info -->
<img class="img-responsive profile" src="<?php echo $profile_pic; ?>">
</div><!-- close col -->
<div class="col-xs-8 col-xs-offset-1 right-column">
<h1 class="title text-center"><?php echo $cf_property_title; ?></h1>
<p class="mls text-center">MLS <?php echo $mls_number;?></p>
<div class="row icons">
<div class="col-xs-3 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/bed.svg">
<p><?php echo $bedrooms;?> Bedrooms</p>
</div><!-- close col -->
<div class="col-xs-3 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/bath.svg">
<p><?php echo $bathrooms;?> Baths</p>
</div><!-- close col -->
<div class="col-xs-3 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/plan.svg">
<p><?php echo $square_feet;?> Sq. Ft.</p>
</div><!-- close col -->
<div class="col-xs-3 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/garage.svg">
<p><?php echo $garage;?> Car Garage</p>
</div><!-- close col -->
</div><!-- close row -->
<div class="overview">
<h4 class="sub">Highlights</h4>
<?php echo $property_description ?>
</div><!-- close overview -->
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
<!-- ==================== -->
<!-- end of flyer section -->
<!-- ==================== -->
<?php
} else {
// load normal landing-1
?>
<!-- ==================== -->
<!-- landing page section -->
<!-- ==================== -->
<header>
<div class="above-nav">
<div class='main-image-wrap limit'>
<img class="img-responsive" src='<?php echo $main_banner_image ?>' />
<div class='main-image-overlay'>
<h2 class='title text-center'><?php echo $cf_property_title; ?></h2>
<h4 class='subtitle text-center'><?php echo $cf_property_address; ?></h4>
</div><!-- end description div -->
</div><!-- close main-image-wrap -->
</div><!-- close above-nav -->
<div class="nav-wrapper" style="height:51px;"> <!-- Prevents content jump when navbar becomes fixed -->
<nav class="navbar navbar-default navbar-inverse" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="">
<ul class="nav navbar-nav">
<!-- <li class="pull-left"><a href="#">logo</a></li> -->
<li class=""><a href="#overview">Overview</a></li>
<li><a href="#photos">Photos</a></li>
<?php
if( !empty($matterport_iframe) ): ?>
<li><a href="#matterport">Matterport 3D Tour</a></li>
<?php endif; ?>
<li><a href="#map">Map</a></li>
<li><a href="#area">About The Area</a></li>
<li><a href="#contact-section">Contact</a></li>
<li class="social pull-right"><a href="#social">Social Links</a></li>
<li class='pull-right'><a href="?subpage=flyer" target="_new">Print Version</a></li>
<?php
if($floor_plan){
echo "<li class='pull-right'><a href='".$floor_plan."' target='_new'>Floor Plan</a></li>";
}
?>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
</header>
<section class="overview" id="overview">
<div class="container">
<h2 class="section-title">Property Overview</h2>
<h3 class="list-price"><?php echo $listing_price; ?></h3>
<?php
if ($mls_number){
echo "<p class='mls'> MLS: ".$mls_number.'</p>';
}
?>
<div class="row icons">
<div class="col-xs-3 col-md-2 col-md-offset-2 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/bed.svg">
<p><?php echo $bedrooms; ?> Bedrooms</p>
</div><!-- close col -->
<div class="col-xs-3 col-md-2 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/bath.svg">
<p><?php echo $bathrooms; ?> Baths</p>
</div><!-- close col -->
<div class="col-xs-3 col-md-2 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/plan.svg">
<p><?php echo $square_feet; ?> Sq. Ft.</p>
</div><!-- close col -->
<?php
if($garage){
?>
<div class="col-xs-3 col-md-2 detail">
<img class="img-responsive" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/icons/garage.svg">
<p><?php echo $garage; ?> Car Garage</p>
</div><!-- close col -->
<?php
}
?>
</div><!-- close row -->
<div class="row short-description">
<div class="col-xs-12 col-md-8 col-md-offset-2 text-justify">
<?php echo $property_description; ?>
</div><!-- close col -->
</div><!-- close row -->
<!-- property details section can go here -->
</div><!-- close container -->
</section>
<section id="photos">
<div class="container">
<h2 class="section-title">Photos</h2>
<div class="panel " id="togglePanel">
<div class="text-center">
<div class="btn-group btn-group-lg btn-toggle">
<!-- <button class="btn active btn-info" data-toggle="tab" data-target="#gallery-carousel">Slides</button>
<button class="btn btn-default" data-toggle="tab" data-target="#gallery-thumbs">Gallery</button> -->
<ul class="nav nav-tabs">
<li><button class="btn btn-default" data-toggle="tab" data-target="#gallery-carousel">Carousel</button></li>
<li class="active"><button class="btn btn-default" data-toggle="tab" data-target="#gallery-thumbs">Gallery</button></li>
</ul>
</div>
</div>
<div class="panel-body tab-content">
<!-- carousel section -->
<div class="tab-pane" id="gallery-carousel">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
$carousel = get_field('gallery');
if( $carousel ):
$i = 0;
foreach( $carousel as $item ):
// if first item make active
if ($i == 0) { ?>
<div class="item active">
<img src="<?php echo $item['url']; ?>" alt="<?php echo $item['alt']; ?>">
<div class="carousel-caption"><?php echo $item['caption']; ?></div>
</div><!-- close item -->
<?php
}
else{
?>
<div class="item">
<img src="<?php echo $item['url']; ?>" alt="<?php echo $item['alt']; ?>">
<div class="carousel-caption"><?php echo $item['caption']; ?></div>
</div><!-- close item -->
<?php
}
$i++;
endforeach;
endif; ?>
</div><!-- close carousel-inner -->
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- close carousel -->
</div><!-- close tab-pane gallery-carousel -->
<!-- end carousel section -->
<!-- thumbnail gallery section -->
<div class="tab-pane active" id="gallery-thumbs">
<div class="content-holder">
<div class="container">
<div class="row">
<?php
$images = get_field('gallery');
// (thumbnail, medium, large, full or custom size)
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<div class="col-xs-6 col-sm-4 col-md-3 gallery-img">
<a href="#">
<img class="thumbnail img-responsive img-rounded " src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>">
</a>
</div><!-- close col -->
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<!-- lightbox modal -->
<div class="modal" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<div id="modalCarousel" class="carousel">
<div class="carousel-inner"></div>
<a class="carousel-control left" href="#modalCarousel" data-slide="prev">
<i class="glyphicon glyphicon-chevron-left"></i>
</a>
<a class="carousel-control right" href="#modalCarousel" data-slide="next">
<i class="glyphicon glyphicon-chevron-right"></i>
</a>
</div>
</div>
</div>
</div>
</div>
<!-- end lightbox modal -->
</div><!-- close tab-pane gallery-thumbs -->
<!-- thumbnail gallery section -->
</div><!-- close panel-body tab-content -->
</div><!-- close panel -->
</div><!-- close container -->
</section>
<?php
if( !empty($matterport_iframe) ): ?>
<section class="matterport" id="matterport">
<div class="container">
<h2 class="section-title">Matterport 3D Tour</h2>
<div class="row example">
<div class="col-sm-12">
<div class="embed-responsive embed-responsive-16by9">
<!-- iFrame-->
<?php echo $matterport_iframe; ?>
</div>
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
<?php endif; ?>
<!-- custom map section -->
<section id="map">
<div class="map-responsive">
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile; // End of the loop.
?>
</div>
</section>
<section class="about-area" id="area">
<div class="container">
<h2 class="section-title">About The Area</h2>
<div class="row">
<div class="col-sm-5 col-md-5">
<?php
if( !empty($area_image) ): ?>
<img class="img-responsive img-circle img-thumbnail" src="<?php echo $area_image['url']; ?>" alt="<?php echo $area_image['alt']; ?>" />
<?php endif; ?>
</div><!-- close col -->
<div class=" col-sm-7 col-md-7">
<h3><?php echo $area_title; ?></h3>
<?php echo $area_description; ?>
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
<!-- contact info -->
<?php
//contact info
$first_name = get_the_author_meta('first_name');
$last_name = get_the_author_meta('last_name');
$id = get_the_author_meta('ID');
$author_id = "user_".$id;
$agency = get_field('agency', $author_id );
$website_url = get_field('website_url', $author_id);
$email_address = get_field('email_address', $author_id);
$phone_main = get_field('phone_main', $author_id);
$cell_phone = get_field('cell_phone', $author_id);
$fax_number = get_field('fax_number', $author_id);
$street_address = get_field('street_address', $author_id);
$address_line_2 = get_field('address_line_2', $author_id);
$city = get_field('city', $author_id);
$zipcode = get_field('zipcode', $author_id);
$profile_pic = get_field('profile_pic', $author_id);
$email_address = get_field('email_address', $author_id);
?>
<section class="contact-block" id="contact-section">
<div class="container">
<div class="row" id="contact">
<div class="col-sm-3 col-md-2 text-center profile-img">
<img class="img-responsive img-thumbnail img-rounded" src="<?php echo $profile_pic; ?>">
<p><?php echo $first_name." ".$last_name; ?></p>
<p><?php echo $agency;?></p>
</div>
<div class="col-sm-4 ">
<div class="title">
<h3>Contact Info</h3>
</div>
<div class="address">
<ul class="contact-address">
<li>
<i class="fa fa-globe"></i>
<?php echo $website_url; ?>
</li>
<?php
if($street_address && $city && $zipcode):
?>
<li>
<i class="fa fa-map-marker"></i>
<?php echo $street_address;?><br>
<?php
if($address_line_2):
echo $address_line_2."<br>";
endif;
echo $city.", FL ".$zipcode; ?>
</li>
<?php endif; ?>
<li>
<i class="fa fa-phone"></i>
p. <?php echo $phone_main; ?>
</li>
<li>
<i class="fa fa-fax"></i>
f. <?php echo $fax_number; ?>
</li>
<li>
<i class="fa fa-envelope"></i>
<?php echo $email_address; ?>
</li>
</ul>
</div>
</div><!-- close col -->
<div class="col-sm-6 col-md-5 col-md-offset-1 ">
<div class="title">
<h3>Contact Form</h3>
</div>
<form role="form" id="contactForm">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control" id="fName" name="fName" placeholder="First Name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control" id="lName" name="lName" placeholder="Last Name">
</div>
</div>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
</div>
<div class="form-group">
<textarea id="description" name="description" class="form-control" rows="3" placeholder="Your Comments"></textarea>
</div>
<input type="hidden" name="realtor" id="realtor" value="<?php echo $first_name." ".$last_name; ?>">
<input type="hidden" name="authorEmail" id="authorEmail" value="<?php echo $email_address; ?>">
<input type="hidden" name="property" id="property" value="<?php echo $cf_property_address; ?>">
<input type="hidden" name="page" id="page" value="<?php echo get_permalink(); ?>">
<input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
<div class="g-recaptcha" data-sitekey="6LdMEEAUAAAAAMVWGRniq9FYwBpmHtQF6xWf3Het"></div>
<div id="confirmation"></div>
<input type="submit" value="Submit" class="btn btn-info">
</form>
</div><!-- close col -->
</div><!-- close row -->
<hr>
<div class="row" id="social">
<div class="col-sm-8 col-sm-offset-2 text-center">
<h4>Share this listing on your favorite social media network</h4>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style text-center">
<ul class="list-inline">
<li><a class="a2a_dd" href="https://www.addtoany.com/share"></a></li>
<li><a class="a2a_button_facebook"></a></li>
<li><a class="a2a_button_twitter"></a></li>
<li><a class="a2a_button_google_plus"></a></li>
<li><a class="a2a_button_pinterest"></a></li>
<li><a class="a2a_button_linkedin"></a></li>
<li><a class="a2a_button_google_gmail"></a></li>
<li><a class="a2a_button_facebook_messenger"></a></li>
<li><a class="a2a_button_houzz"></a></li>
</ul>
</div>
<script async src="https://static.addtoany.com/menu/page.js"></script>
</div><!-- close col -->
</div><!-- close row -->
</div><!-- close container -->
</section>
<?php get_footer(); ?>
<!-- ==================== -->
<!-- end landing page section -->
<!-- ==================== -->
<?php
}//end else
?>
Here is the final page. If you click the flyer link on the nav bar it opens the printable flyer in a new window.
http://941.media/1234-main-street-sarasota-florida-34231/
Hope that helps
John,
Can’t thank you enough for the thorough response—I sincerely appreciate it.
If you wouldn’t mind taking a look:
I’ve put together a couple of answers I’ve received from the devs (attached) of the Community Events plugin, as well as some of the resources and documentation they point to.
Additionally, here is the untouched template file that I believe additional fields can be added to:
<?php
/**
* Event Submission Form
* The wrapper template for the event submission form.
*
* Override this template in your own theme by creating a file at
* [your-theme]/tribe-events/community/edit-event.php
*
* @since 3.1
* @version 4.5
*
* @var int|string $tribe_event_id
*/
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! isset( $tribe_event_id ) ) {
$tribe_event_id = null;
}
?>
<?php tribe_get_template_part( 'community/modules/header-links' ); ?>
<?php do_action( 'tribe_events_community_form_before_template', $tribe_event_id ); ?>
<form method="post" enctype="multipart/form-data" data-datepicker_format="<?php echo esc_attr( tribe_get_option( 'datepickerFormat', 0 ) ); ?>">
<input type="hidden" name="post_ID" id="post_ID" value="<?php echo absint( $tribe_event_id ); ?>"/>
<?php wp_nonce_field( 'ecp_event_submission' ); ?>
<?php tribe_get_template_part( 'community/modules/title' ); ?>
<?php tribe_get_template_part( 'community/modules/description' ); ?>
<?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
<?php tribe_get_template_part( 'community/modules/image' ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => Tribe__Events__Main::TAXONOMY ) ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => 'post_tag' ) ); ?>
<?php tribe_get_template_part( 'community/modules/venue' ); ?>
<?php tribe_get_template_part( 'community/modules/organizer' ); ?>
<?php tribe_get_template_part( 'community/modules/website' ); ?>
<?php tribe_get_template_part( 'community/modules/custom' ); ?>
<?php tribe_get_template_part( 'community/modules/cost' ); ?>
<?php tribe_get_template_part( 'community/modules/spam-control' ); ?>
<?php tribe_get_template_part( 'community/modules/submit' ); ?>
</form>
<?php do_action( 'tribe_events_community_form_after_template', $tribe_event_id ); ?>
Here is the Events Calendar Themer’s Guide (Community Events is considered an Add-On to The Events Calendar plugin): https://theeventscalendar.com/knowledgebase/themers-guide/
I found the above code in /wp-content/plugins/the-events-calendar-community-events/src/views/community/edit-event.php
Does this make sense? If that is the correct location for the ACF hook, how/where would I place it? The field group I would like to add is titled “Event Proposals” but, for whatever reason, when I use inspector, the div id comes up as “acf-group_59dd13c80be9e” so I’m not sure if that’s what needs to be used in the hook.
I was unsuccessful with the following code:
<?php
/**
* Event Submission Form
* The wrapper template for the event submission form.
*
* Override this template in your own theme by creating a file at
* [your-theme]/tribe-events/community/edit-event.php
*
* @since 3.1
* @version 4.5
*
* @var int|string $tribe_event_id
*/
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! isset( $tribe_event_id ) ) {
$tribe_event_id = null;
}
?>
<?php tribe_get_template_part( 'community/modules/header-links' ); ?>
<?php do_action( 'tribe_events_community_form_before_template', $tribe_event_id ); ?>
<form method="post" enctype="multipart/form-data" data-datepicker_format="<?php echo esc_attr( tribe_get_option( 'datepickerFormat', 0 ) ); ?>">
<input type="hidden" name="post_ID" id="post_ID" value="<?php echo absint( $tribe_event_id ); ?>"/>
<?php wp_nonce_field( 'ecp_event_submission' ); ?>
<?php tribe_get_template_part( 'community/modules/title' ); ?>
<?php acf_form( $options );
$settings = array(
/* (string) Unique identifier for the form. Defaults to 'acf-form' */
'id' => 'acf-group_59dd13c80be9e',
/* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */
'form' => false
);?>
<?php tribe_get_template_part( 'community/modules/description' ); ?>
<?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
<?php tribe_get_template_part( 'community/modules/image' ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => Tribe__Events__Main::TAXONOMY ) ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => 'post_tag' ) ); ?>
<?php tribe_get_template_part( 'community/modules/venue' ); ?>
<?php tribe_get_template_part( 'community/modules/organizer' ); ?>
<?php tribe_get_template_part( 'community/modules/website' ); ?>
<?php tribe_get_template_part( 'community/modules/custom' ); ?>
<?php tribe_get_template_part( 'community/modules/cost' ); ?>
<?php tribe_get_template_part( 'community/modules/spam-control' ); ?>
<?php tribe_get_template_part( 'community/modules/submit' ); ?>
</form>
<?php do_action( 'tribe_events_community_form_after_template', $tribe_event_id ); ?>
If there’s any other information I can provide, I’d be more than happy to do so.
Thanks so much!
Hi John, thanks for your reply.
1) acf_form_head()
is the first function on my template file, as <?php acf_form_head(); get_header(); the_post(); ?>
2) No JS errors were returned in the console when trying to load taxonomies. Is there a need/method to turn on any verbose logging?
3) Turning on WP_DEBUG and WP_DEBUG_LOG didn’t return any errors on the page or in my logs.
I tried creating a fresh WP install at http://acftax.wpengine.com/?p=1 with the default 2017 theme. Everything is vanilla except for code inside the loop. single.php
‘s code in its entirety is attached.
<?php acf_form_head(); get_header(); ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
echo '// START <code>acf_form()</code>';
acf_form(array(
'post_id' => $post->ID
));
echo '// END <code>acf_form()</code>';
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div><!-- .wrap -->
<?php get_footer();
And I still get the same error, leading me to believe this is an issue within ACF or Select2.
Any additional assistance on this would be greatly appreciated. Thanks!
I’ll try. But I’m repeating my self here. But maybe this will clarify.
This is my ACF form:
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'db_test',
'post_status' => 'publish'
),
'submit_value' => 'Create a new event',
// 'return' => '/wp-content/themes/MY_THEME/includes/new-employee.php'
)); ?>
<?php endwhile; ?>
</div>
</div>
It gives me this HTML
<form id="acf-form" class="acf-form" action="" method="post">
<div class="acf-fields acf-form-fields -top">
<div id="Firstname" class="acf-field acf-field-text acf-field-5968834df2ac1 voornaam" style="width:40%;" data-name="voornaam" data-type="text" data-key="field_5968834df2ac1" data-width="40">
<div class="acf-label">
<label for="acf-field_5968834df2ac1">Voornaam</label>
</div>
<div class="acf-input">
<div class="acf-input-wrap"><input type="text" id="acf-field_5968834df2ac1" class="" name="acf[field_5968834df2ac1]" value="" placeholder="" /></div> </div>
</div>
</div>
<div class="acf-form-submit">
<input type="submit" class="acf-button button button-primary button-large" value="Create a new event" /> <span class="acf-spinner"></span>
</div>
</form>
All I want is when you click on submit it writes the entry to the WP database and returns the value of this acf[field_5968834df2ac1]
field using an echo.
Im trying to do that using this code:
<?php
$FirstName = $_POST['acf']['field_5968834df2ac1'];
echo 'data' . $FirstName; ?>
But that doesn’t give me any results. So my question was/is how do I get the value of this field when I clicked on submit and the page reloads.
Here is my whole code:
<?php acf_form_head(); ?>
<?php /* Template name: Nieuwe Collega's */ get_header(); ?>
<?php session_start();
$_SESSION['foo'] = $_POST['acf']['field_5968834df2ac1'];
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'db_test',
'post_status' => 'publish'
),
'submit_value' => 'Create a new event',
// 'return' => '/wp-content/themes/intranetpuur/includes/new-employee.php'
)); ?>
<?php endwhile; ?>
</div>
</div>
<?php
$FirstName = $_POST['acf']['field_5968834df2ac1'];
echo 'data' . $FirstName;
echo $_SESSION['foo'];
?>
<?php get_footer(); ?>
Thanks for the continued help, much appreciated!
I think I was able to get it working by altering the code to display the gallery in my template file. Instead of using:
echo do_shortcode('[gallery orderby="menu_order" link="none" size="large" columns="1"]')
I’m now using:
<?php if ( '' !== ( $gallery = get_post_meta( get_the_ID(), 'project_gallery', true ) ) ) : ?>
<section class="project-gallery">
<?php echo do_shortcode( $gallery ); ?>
</section>
<?php endif; ?>
The ‘if’ statement was already wrapping my original code, I just wasn’t taking advantage of it properly. Someone else had started this plugin for us, and I was just trying to get it working (with my limited PHP knowledge).
It now functions just like a gallery added to the main content area, so we do have to make sure all variables are accounted for there (e.g, link=none, size=large, etc.). But this is fine.
Solution:
Note that there’s an IF and an ENDIF which need to be wrapped around the ACF fields.
Also note that the default WP the_content() code must remain in place — even if you’re not using it for content in your template.
<div class="entry-content clearfix">
<!-- HIDES ACF FIELDS for use with WP password protect feature -->
<?php if( !post_password_required( $post )): ?>
<h2><?php the_field( 'business_name' ); ?></h2>
<p><?php the_field( 'client_name' ); ?></p>
<p><small><?php the_field( 'date' ); ?></small></p>
<h1><?php the_field( 'introduction_title' ); ?></h1>
<p><?php the_field( 'introduction_text' ); ?></p>
<!-- ENDS HIDE ACF FIELDS with WP Password Protect -->
<?php endif; ?>
<?php the_content(); ?>
</div><!-- .entry-content -->
Hi Guys
I am trying to achieve like this.. I am trying to show a post object as repeater inside 2 nested repeater field.. I am using this repeater and post object in a page template called page-bagels.php . These 2 repeater showing the 2 row as output as expected. But the post object is not showing or not returning value. Rather it is returning value of the page. Like where I have used <?php the_title(); ?> it is returning the page title and not returning the post object title. My code is as below
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-content">
<div class="main-wrap">
<div class="col-sm-12">
<div class="breadcrumbs">
<?php if(function_exists('bcn_display')) { bcn_display(); }?>
</div> <!-- breadcrambs ends here -->
</div><!-- col-sm-12 ends here -->
<?php // check for rows (parent repeater)
if( have_rows('product_page') ): ?>
<div class="col-lg-12 row product-row">
<?php
// loop through rows (parent repeater)
while( have_rows('product_page') ): the_row(); ?>
<div class="col-sm-12">
<div class="marque">
<span class="brand-lg"><img src="<?php the_sub_field('brand_image'); ?>" /></span> </div>
</div>
<?php
// check for rows (sub repeater)
if( have_rows('post_repeater') ): ?> <div class="col-sm-12 product-item-row">
<?php
// loop through rows (sub repeater)
while( have_rows('post_repeater') ): the_row();?>
<div class="col-sm-3 product-item">
<?php $postobject = get_sub_field('product_post'); ?>
<a href="<?php $postURL = get_permalink($postobject->ID);?>">
<img class="product-img" src="<?php bloginfo('template_directory');?>/images/product-images/321600_moelleux_blanc_trepais.png" width="100%" />
<p class="product-name"><?php the_title();?></p>
<p class="product-seemore">See More</p> </a>
</div><!-- col ends here -->
<?php endwhile; ?>
</div><!-- col Product Items row here -->
<?php endif; //if( get_sub_field('items') ): ?>
<?php endwhile; // while( has_sub_field('to-do_lists') ): ?>
</div><!-- col lg 12 ends here or row ends here -->
<?php endif; // if( get_field('to-do_lists') ): ?>
<?php endwhile; // end of the loop. ?>
</div><!-- main wrap ends here -->
<div class="clr"></div>
</div><!-- main content ends here -->
So in this code you can see the post object is also a repeater.. So it means I am using 3 repeaters. If you see the code you will get it
Here is the output I am getting http://ahsanurrahman.com/myprojects/cms/wp/gadoua/en/bagels/
So any help is appreciated.
Oooof…thought I’d responded to this days ago. My apologies.
First, $quote is just a text field – a testimonial from a client. Second, I’m not sure how to export the json of the field group. Third, following is the full code for the shortcode. Note that I’ve since made a number of changes as I continued to work on things, but I still haven’t figured out how to get the quotes pulled in so I had temporarily pulled the code entirely. So where it says “Quote goes here”, that’s where the code above was.
<?php
//Add Featured Portfolio items shortcode //
add_shortcode( 'featured_portfolio', 'display_featured_portfolio_items' );
function display_featured_portfolio_items(){
ob_start();
// Define the query
$args = array(
'post_type' => 'pixieportfolio',
'post_status' => 'publish',
'orderby' => 'menu_order',
'meta_query' => array(
array(
'key' => 'featured_portfolio_item',
'value' => '1',
'compare' => '=',
)
),
'meta_key' => '_thumbnail_id',
'posts_per_page' => 999
);
$query = new WP_Query( $args );
$count = 0;
// Carousel // ?>
<!--<div class="more-button">
<a href="/portfolio-all/" class="btn btn-default btn-lg" type="button" role="button">More Projects</a>
</div>-->
<div id="featuredCarousel" class="carousel slide" data-ride="carousel" data-pause="hover">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php while($query->have_posts()): $query->the_post(); ?>
<li <?php if($count == 0){ echo 'class="active"';} ?> data-target="#featuredCarousel" data-slide-to="<?php echo $count++; ?>"></li>
<?php endwhile; ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php $count = 0;
while ($query->have_posts()) : $query->the_post();
$count++;
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'pp-home-portfolio' );
$url = $thumb['0'];
$values = get_field('tech_choices');
$terms = get_the_terms($post->ID, 'post_tag');
$custom = get_post_custom($post->ID);
$caption = get_field('caption', '');
$client = get_field('client', '');
$project_url = get_field('project_url', '');
$date = get_field('date', ''); ?>
<!-- Wrapper for slides -->
<div class="item <?php if ($count == 1) { echo 'active';} ?>" data-slide-number="<?php echo $count++; ?>" id="<? the_ID(); ?>">
<div class="item-image" style="background-image: url(<?=$url?>);" title="<?php the_title() ?>" data-toggle="modal" data-target="#myModal<?php echo $count; ?>"></div>
<div class="project-details">
<div class="project-detail-border shadow-effect"></div>
<div class="project-detail">
<div class="top-detail">
<h4><?php the_title(); ?></h4>
<div class="short-description">
<?php $content = get_the_content();
echo wp_trim_words( $content , '20' );
?>
</div>
</div>
<table class="table project">
<tr>
<td valign="middle" class="fifty">
<?php $terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'pixie-portfolio-categories', '', ', ', '' ) );
echo $terms_as_text;?>
</td>
<td valign="middle" class="fifty">
<?php if( $values ) {
if(in_array('WordPress', $values )){ ?>
<i class="fa fa-wordpress fa-2x" data-toggle="tooltip" title="Wordpress"></i>
<?php } if(in_array('HTML-5', $values )){ ?>
<i class="fa fa-html5 fa-2x" data-toggle="tooltip" title="HTML-5"></i>
<?php } if(in_array('CSS-3', $values )){ ?>
<i class="fa fa-css3 fa-2x" data-toggle="tooltip" title="CSS-3"></i>
<?php } if(in_array('Sportswear', $values )){ ?>
<i class="fa fa-bicycle fa-2x" data-toggle="tooltip" title="Sportswear"></i>
<?php } if(in_array('Adobe', $values )){ ?>
<i class="fa fa-paint-brush fa-2x" data-toggle="tooltip" title="Adobe"></i>
<?php } if(in_array('Code', $values )){ ?>
<i class="fa fa-code fa-2x" data-toggle="tooltip" title="Code"></i>
<?php } if(in_array('Ecommerce', $values )) { ?>
<i class="fa fa-database fa-2x" data-toggle="tooltip" title="MySQL"></i>
<?php }
} else {} ?>
</td>
</tr>
<tr>
<td colspan="2" class="more-info" data-toggle="modal" data-target="#myModal<?php echo $count; ?>">
<div class="view-project">View Project</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<!-- Modal -->
<div id="myModal<?php echo $count; ?>" class="modal fade" role="dialog" aria-labelledby="myModal<?php echo $count; ?>Label">
<div class="modal-dialog modal-lg" role="document">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title"><?php the_title() ?></h2>
<span>
<?php if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li><a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a></li>
<?php $icon = get_field('creative_icon', $term->taxonomy . '_' . $term->term_id); echo $icon; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</span>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-8">
<div>
<p class="post-meta gallery-list">
<?php if( $client ): ?>
<span class="pixie-date">
<span class="title">Client:</span> <?=$client?>
</span>
<?php endif;
if ( $date ): ?>
<span class="post-cats">
<span class="title">Date:</span> <?=$date?>
</span>
<?php endif;
if ( $values ) { ?>
<span class="post-comments">
<?php $values = get_field('tech_choices'); ?>
<span class="title">Tech used in this project:</span>
<?php if(in_array('WordPress', $values )){ ?>
<i class="fa fa-wordpress fa-2x" data-toggle="tooltip" data-placement="bottom" title="WordPress"></i>
<? }
if(in_array('HTML-5', $values )){ ?>
<i class="fa fa-html5 fa-2x" data-toggle="tooltip" data-placement="bottom" title="HTML5"></i>
<? }
if(in_array('CSS-3', $values )){ ?>
<i class="fa fa-css3 fa-2x" data-toggle="tooltip" data-placement="bottom" title="CSS3"></i>
<? }
if(in_array('Sportswear', $values )){ ?>
<i class="fa fa-bicycle fa-2x" data-toggle="tooltip" data-placement="bottom" title="Sportswear"></i>
<? }
if(in_array('Adobe', $values )){ ?>
<i class="fa fa-paint-brush fa-2x" data-toggle="tooltip" data-placement="bottom" title="Illustrator and/or Photoshop"></i>
<? }
if(in_array('Code', $values )){ ?>
<i class="fa fa-code fa-2x" data-toggle="tooltip" data-placement="bottom" title="PHP, JQuery, etc."></i>
<? }
if(in_array('Ecommerce', $values )){ ?>
<i class="fa fa-shopping-cart fa-2x" data-toggle="tooltip" data-placement="bottom" title="ECommerce"></i>
<? }
if(in_array('MySQL', $values )){ ?>
<i class="fa fa-database fa-2x" data-toggle="tooltip" data-placement="bottom" title="MySQL"></i>
<? } ?>
</span>
<?php } ?>
</p>
</div>
<?php echo the_content(); ?>
<blockquote class="testimonial">
QUOTE GOES HERE
</blockquote>
</div>
<div class="col-md-4">
<div class="gallery">
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'darwin-modal-main' );
$url = $thumb['0'];
$thumb2 = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );
$url2 = $thumb2['0'];
$c = 0; ?>
<a href="<?=$url2?>" class="group" id="port_gal" rel="group<?php echo $c; ?>">
<img src="<?=$url?>" width="300" height="300">
</a>
<?php $images = get_field('gallery_images');
if( $images ) {
foreach( $images as $image ) {
?>
<a href="<?php echo $image['sizes']['large'] ?>" class="group" id="port_gal" rel="group<?php echo $c; ?>">
<img src="<?php echo $image['sizes']['darwin-modal-thumb'] ?>" alt="<?php $image['alt'] ?>" />
</a>
<?php }
} ?>
</div>
<div class="website-button">
<?php if ( $project_url ): ?>
<a class="btn btn-default" href="<?=$project_url?>" target="_blank" role="button">Visit Website</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_query(); ?>
</div>
<?php return ob_get_clean(); } ?>
Here is an example of useage in a loop. It’s not particularly long so I’m just pasting it here. Relevant code is on line 64, JSON is attached.
<?php
/*
Template Name: Current Semester
*/
get_header('courses');
$semester = get_field('current_semester', 'option');
?>
<div class="content width" role="main">
<div class="page">
<?php get_sidebar('courses'); ?>
<section class="content-container">
<div id="regular-content">
<!-- Undergraduate -->
<?php
$ud_args = array(
'post_type' => 'courses',
'taxonomy' => 'courses-category',
'field' => 'term_id',
'terms' => $semester,
'meta_query' => array(
array(
'key' => 'course_number',
'value' => array( 100, 199 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
),
'meta_key' => 'course_number',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page' => '60'
);
$ud_query = new WP_Query($ud_args);
if($ud_query->have_posts()) : ?>
<h2 class="course-level-header">Undergraduate</h2>
<div class="courselist_content">
<?php while($ud_query->have_posts()) :
$ud_query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" class="group course-list-wrapper">
<header class="index-header">
<h1 class="course-title">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'thales' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_field('language_prefix'); ?> <?php the_field('course_number_prefix'); ?> <?php the_field('course_number'); ?><?php the_field('course_number_suffix'); ?>: <?php the_title(); ?>
</a>
</h1>
</header><!-- .entry-header -->
<div class="course-content">
<p class="section-spacing">
<?php the_field('timeframe'); ?> <span class="course-details"><?php the_field ('location'); ?></span>
<span class="course-details"><b>Instructor: <?php $post_object = get_field('instructor', $post->ID); ?> <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo $post_object->post_title; ?></a></p>
</b></span>
</p>
<?php the_content(__(' » read more »'));?>
<p class="section-spacing">Course Catalog Number: <?php the_field ('ccn'); ?></p>
</div><!-- .course-content -->
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</section><!-- #content-container -->
</div>
</div>
<?php get_footer(); ?>
I’m feeling pretty dense right about now. Honestly, I’m trying to get this figured out, and have looked at the links you’ve sent and tried a ridiculous number of combinations of things. But now the title isn’t working at all.
I removed the section from functions that you said was no longer necessary. Replaced it with what’s below.
The new title shows properly in the body of the resulting post page, but it isn’t reflected as either the title or the slug. So, for instance, the latest new post from this form resulted in a slug of “vbsform/3024-2/”, instead of “vbsform/title-start_date/”
Functions.php
//Auto add and update Title field:
function vbs_post_title_updater( $post_id ) {
// get the church name
$new_title_church_name = get_field('church_name', $post_id);
// get the selected date and the current date
$new_title_date = get_field('start_date', $post_id);
$new_title_date = new DateTime($new_title_date);
// set the title
$new_title = $new_title_church_name . ' - ' . $new_title_date->format('M j, Y');
// create the update data holder
$vbs_post = array();
$vbs_post['ID'] = $post_id;
$vbs_post['title'] = $new_title;
//Unhook function to prevent infitnite looping
remove_action('acf/save_post', 'vbs_post_title_updater', 20);
//Rehook function to prevent infitnite looping
add_filter('acf/save_post', 'vbs_post_title_updater', 20);
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'vbs_post_title_updater', 20);
Form Page
<?php
function my_kses_post( $value ) {
// is array
if( is_array($value) ) {
return array_map('my_kses_post', $value);
}
// return
return wp_kses_post( $value );
}
add_filter('acf/update_value', 'my_kses_post', 10, 1);
add_action( 'get_header', 'cmin_do_acf_form_head', 1 );
function cmin_do_acf_form_head() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
acf_form_head();
}
add_action( 'wp_print_styles', 'cmin_deregister_admin_styles', 999 );
function cmin_deregister_admin_styles() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
wp_deregister_style( 'wp-admin' );
}
get_header(); ?>
<div class="page-wrapper">
<div class="row">
<div id="content" class="large-12 columns" role="main">
<?php /* The loop */
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo '<p>You must be a registered author to post.</p>';
return;
}
$vbs_post = array(
'post_id' => 'new_post',
'post_title' => wp_strip_all_tags($new_title),
'post_content' => false,
'form' => true,
'new_post' => array(
'post_type' => 'vbsform',
'post_status' => 'publish'
),
'field_groups' => array(2793),
'return' => '%post_url%',
'submit_value' => 'Submit VBS Event',
'updated_message' => 'Saved!',
'post_title' => wp_strip_all_tags($new_slug),
);
acf_form( $vbs_post );
</div><!-- #content -->
</div><!-- #row -->
</div><!-- #page-wrapper -->
<?php acf_enqueue_uploader(); ?>
<script type="text/javascript">
(function($) {
// setup fields
acf.do_action('append', $('#popup-id'));
})(jQuery);
</script>
<?php get_footer(); ?>
Results Page
<?php
function my_kses_post( $value ) {
// is array
if( is_array($value) ) {
return array_map('my_kses_post', $value);
}
// return
return wp_kses_post( $value );
}
add_filter('acf/update_value', 'my_kses_post', 10, 1);
add_action( 'get_header', 'cmin_do_acf_form_head', 1 );
function cmin_do_acf_form_head() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
acf_form_head();
}
get_header();
?>
<?php
// Create big featured image if set
if($flatsome_opt['blog_post_style'] == 'big-featured-image') { ?>
<div class="parallax-title">
<?php while ( have_posts() ) : the_post(); ?>
<?php ob_start(); ?>
<header class="entry-header text-center">
<div class="tx-div small"></div>
<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php the_date('F j, Y', 'Submitted on ', ''); ?>
</div>
</header>
<?php endwhile; // end of the loop. ?>
</div>
<?php } ?>
<div class="page-wrapper page-<?php echo $flatsome_opt['blog_post_layout']; ?>">
<div class="row">
<div class="page-inner">
<?php /* The loop */
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo '<p>You must be a registered author to post.</p>';
return;
} ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if($flatsome_opt['blog_post_style'] == 'default' || !isset($flatsome_opt['blog_post_style'])) { ?>
<header class="entry-header text-center">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="tx-div small"></div>
<div class="entry-meta">
<?php the_date('F j, Y', 'Submitted on ', ''); ?> by <?php the_author(); ?><br>
This post was last modified by <?php the_modified_author(); ?> on <?php the_modified_date('F j, Y'); ?> at <?php the_modified_date('g:i a'); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<?php $author_id = get_the_author_meta('ID');
$author_phone = get_field('phone_number', 'user_'. $author_id );
$term = get_field('conference');
$start_date = get_field('start_date', false, false);
$start_date = new DateTime($start_date);
$end_date = get_field('end_date', false, false);
$end_date = new DateTime($end_date);
$images = get_field('images');
?>
<table class="table table-striped">
<tr>
<td>Church Name</td>
<td><?php the_field('church_name'); ?> Adventist Church</td>
</tr>
<?php if( $term ): ?>
<tr>
<td>Conference</td>
<td><?php echo $term->name; ?></td>
</tr>
<?php endif; ?>
<tr>
<td>Contact Person</td>
<td><?php the_author(); ?></td>
</tr>
<tr>
<td>E-mail address</td>
<td><?php the_author_meta('user_email'); ?></td>
</tr>
<tr>
<td>Phone Number</td>
<td><?php echo $author_phone; ?></td>
</tr>
<tr>
<td>I am the...</td>
<td><?php the_field('i_am'); ?></td>
</tr>
<tr>
<td>Start Date</td>
<td><?php echo $start_date->format('F j, Y'); ?></td>
</tr>
<tr>
<td>End Date</td>
<td><?php echo $end_date->format('F j, Y'); ?></td>
</tr>
<?php if( $images ) { ?>
<tr>
<td>Images</td>
<td>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['admin-thumb']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php } ?>
</table>
<div class="edit-form">Edit this VBS submission</div>
<div class="vbs-off"><?php acf_form(); ?></div>
</div><!-- .entry-content -->
<script>
$ = jQuery;
$(".edit-form").click(function(){
$(".vbs-off").toggleClass("vbs-on");
$(this).toggleClass("vbs-on");
}, function() {
$(".vbs-off").toggleClass("vbs-on");
});
</script>
</article>
<?php endwhile; // end of the loop. ?>
</div><!-- .page-inner -->
</div><!-- #content -->
<div class="large-3 columns left">
<?php get_sidebar(); }?>
</div><!-- end sidebar -->
</div><!-- end row -->
</div><!-- end page-wrapper -->
<?php acf_enqueue_uploader(); ?>
<script type="text/javascript">
(function($) {
// setup fields
acf.do_action('append', $('#popup-id'));
})(jQuery);
</script>
<?php get_footer(); ?>
Hi there,
I apologize for the delay. The long weekend got away from me.
Ok, here’s where I’m at right now. I’m not sure what I had before our last go-around and what’s been since, so here’s all of it.
functions.php
add_filter('acf/pre_save_post' , 'cmin_do_pre_save_post' );
function cmin_do_pre_save_post( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
}
// Create a new post
$new_title_church_name = $_POST['acf']['field_577c12419eed1'];
$new_title_date = get_field('start_date');
// make date object
$new_title_date = new DateTime($new_title_date);
$new_title = $new_title_church_name . ' - ' . $new_title_date->format('M j, Y');
$new_slug = sanitize_title( $new_title );
$post = array(
'post_type' => 'vbsform', // Your post type ( post, page, custom post type )
'post_status' => 'publish', // (publish, draft, private, etc.)
'post_title' => wp_strip_all_tags($new_slug), // Post Title ACF field key
//'post_content' => $_POST['acf']['field_54dfc94e35ec5'], // Post Content ACF field key
);
// insert the post
$post_id = wp_insert_post( $post );
// Save the fields to the post
do_action( 'acf/save_post' , $post_id );
return $post_id;
}
Form Page
<?php
function my_kses_post( $value ) {
// is array
if( is_array($value) ) {
return array_map('my_kses_post', $value);
}
// return
return wp_kses_post( $value );
}
add_filter('acf/update_value', 'my_kses_post', 10, 1);
add_action( 'get_header', 'cmin_do_acf_form_head', 1 );
function cmin_do_acf_form_head() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
acf_form_head();
}
add_action( 'wp_print_styles', 'cmin_deregister_admin_styles', 999 );
function cmin_deregister_admin_styles() {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
wp_deregister_style( 'wp-admin' );
}
get_header(); ?>
<div class="page-wrapper">
<div class="row">
<div id="content" class="large-12 columns" role="main">
<?php /* The loop */
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo '<p>You must be a registered author to post.</p>';
return;
}
while ( have_posts() ) : the_post();
$new_post = array(
'post_id' => 'new', // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
'field_groups' => array(2793), // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit VBS Event',
'updated_message' => 'Saved!'
);
acf_form( $new_post );
endwhile; ?>
</div><!-- #content -->
</div><!-- #row -->
</div><!-- #page-wrapper -->
<?php acf_enqueue_uploader(); ?>
<script type="text/javascript">
(function($) {
// setup fields
acf.do_action('append', $('#popup-id'));
})(jQuery);
</script>
<?php get_footer(); ?>
Most everything is working swimmingly, except I still cannot seem to get the start_date field to display in the title. It only displays the CURRENT date. Not sure why. I have the field date called. AND I once more have a pre-populated field, and I’m not sure why. I thought that had been solved previously, but it’s back. Grrrrrr
<?php
// check if the flexible content field has rows of data
if( have_rows('flexible_inhalte') ):;?>
<?php
// loop through the rows of data
while ( have_rows('flexible_inhalte') ) : the_row();
if( get_row_layout() == 'flexible_inhalte_kopfbild' ):
$image = get_sub_field('flexible_inhalte_kopfbild')['url'];
echo '<div class="page-fullhead" style="background:url('.$image.');height:450px;max-height:450px;width:100%;background-size:cover;background-position:center;">';
echo '</div>';
echo '<div id="wrapper">';
echo '<div class="container page-main">';
echo '<div class="row">';
elseif( get_row_layout() == 'flexible_inhalte_text' ):
echo '<div class="col-lg-7 col-md-7 col-sm-12 col-xs-12">';
$main_text = get_sub_field('flexible_inhalte_text');
echo $main_text;
echo '</div>';
elseif( get_row_layout() == 'flexible_inhalte_icon' ):
echo '<div class="col-lg-3 col-lg-offset-1 col-md-3 col-md-offset-1 col-sm-12 col-xs-12 side-icon">';
echo '<div class="inner-wrap">';
$main_icon = get_sub_field('flexible_inhalte_icon_icon');
$main_icon_text = get_sub_field('flexible_inhalte_icon_bezeichnung');
echo '<img src='.$main_icon['url'].'>';
echo '<div class="saeulen-text">';
echo $main_icon_text;
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
endif;
endwhile;
else :
// no layouts found
endif;
?>
I would like wrap all row divs into a div container (id=”wrapper”). The sub_field(‘flexible_inhalte_kopfbild’) must be above.
Looks like this
<?php get_header(); ?>
<div id="innerwrapper" class="page">
<div class="container">
<div class="row">
<div id="lewaKolumna" class="col-xs-3 col-sm-3 col-md-3 hidden-xs hidden-sm">
<div class="sideModule">
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(17) ) : else : ?>
<?php endif; ?>
</div>
</div>
<div id="prawaKolumna" role="main" class="col-xs-12 col-sm-9 col-md-9">
<div class="catHeader">
<div id="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>
<div class="headerImg">
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(14) ) : else : ?>
<?php endif; ?>
</div>
<div class="headerCatDesc">
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(15) ) : else : ?>
<?php endif; ?>
</div>
</div>
<div id="podstrona">
<div class="contentBodyWrapper kanalyPremium">
<?php
/* Główna pętla */
$args = array(
'post_type' => 'kanaly_premium',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
);
$fullnewsloop = new WP_Query($args);
if($fullnewsloop->have_posts()):
while($fullnewsloop->have_posts()): $fullnewsloop->the_post(); ?>
<div class="pakietBoxLista row">
<div class="col-xs-12 premiumTitle">
<h2><?php echo the_title(); ?></h2>
</div>
<div class="col-xs-12 col-md-3">
<?php if(get_field('okladka_pakietu_premium')): ?>
<?php $okladkaPremium = get_field('okladka_pakietu_premium'); ?>
<div class="headerImg">
<img src="<?php echo $okladkaPremium['sizes']['medium'] ?>" />
</div>
<?php endif; ?>
</div>
<div class="col-xs-12 col-md-9">
<?php if( get_field('krotki_opis_pakietu_premium')): ?>
<?php the_field('krotki_opis_pakietu_premium'); ?>
<?php endif; ?>
<ul id="pakietBoxLista">
<?php // check current row layout ?>
<?php if( have_rows('programy_lista') ): ?>
<?php while ( have_rows('programy_lista') ) : the_row(); ?>
<?php
$post_objects = get_sub_field('kanal');
if( $post_objects ): ?>
<?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li class="kanalTelwizyjny">
<section class="kanalWrapper">
<?php //Elementy kanału ?>
<?php if(get_field('klasa_obrazka_kanalu', $post->ID)): ?>
<div class="sprite sprite-premium sprite-premium-<?php the_field('klasa_obrazka_kanalu', $post->ID); ?>"></div>
<?php else: ?>
<div class="sprite sprite-premium sprite-premium-<?php echo $post->post_name; ?>"></div>
<?php endif; ?>
<div class="kanalWrapperInner row row-eq-height">
<div class="col-md-3 col-sm-4 imgPrevBlock">
<?php if( get_field('pakiety_dostepne_w', $post->ID)): ?>
<div class="dostepnyW"><p>Dostępne w pakiecie:</p><?php the_field('pakiety_dostepne_w', $post->ID); ?></div>
<?php endif; ?>
<?php if( get_field('dostepny_na_kanale', $post->ID)): ?>
<div class="dostepnyNa"><p>Dostępny na kanale:</p><?php the_field('dostepny_na_kanale', $post->ID); ?></div>
<?php endif; ?>
<?php if( get_field('kategoria_kanalu', $post->ID)): ?>
<div class="kategoriaKanalu"><p>Kategoria:</p><?php the_field('kategoria_kanalu', $post->ID); ?></div>
<?php endif; ?>
<?php if( get_field('jakosc', $post->ID) == "Jakość SD" ): ?>
<div class="wyborJakosci"><p><?php echo get_field('jakosc', $post->ID); ?></p></div>
<?php else: ?>
<div class="wyborJakosci jakoscHD"><p><?php echo get_field('jakosc', $post->ID); ?></p></div>
<?php endif; ?>
</div>
<div class="col-md-9 col-sm-8 shortDescBlock">
<h3 class="catItemTitle">
<?php the_title(); ?>
</h3>
<div class="catItemIntroText listaPremium">
<?php the_content(); ?>
</div>
</div>
</div>
</section>
</li>
<?php endforeach; ?>
<?php // wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
<div class="col-xs-12 col-md-12 readMore">
<a class="btn pull-right" title="więcej" href="<?php echo get_permalink( $post->ID ); ?>">więcej</a>
</div>
</div>
<?php
endwhile;
endif;
?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
Hi John,
Thanks for the response!
I’ve been fiddling with the code that you sent. The good news is with your code, I’m able to get empty rows to show in the repeater field. The not-so-good news is I’m still not able to pre-populate the form rows with values on the front end, nor post the values to the correct pre-existing field.
I’ve noticed that the pre-existing field (‘availability’ field, we’re using WooCommerce Bookings) is wrapping the item in an extra array, such as:
Array ( [0] => Array ( [0] => Array ( [type] => custom [bookable] => yes [priority] => 10 [from] => 2016-02-02 [to] => 2016-02-03 ) [1] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-10 [to] => 2016-02-12 ) [2] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-04 [to] => 2016-02-20 ) ) )
…whereas, the array output from ACF using your code is:
Array ( [0] => Array ( [type] => custom [bookable] => yes [priority] => 10 [from] => 2016-02-02 [to] => 2016-02-03 ) [1] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-10 [to] => 2016-02-12 ) [2] => Array ( [type] => custom [bookable] => no [priority] => 10 [from] => 2016-02-04 [to] => 2016-02-20 ) )
The code I’m using so far:
<?php
/**
* The template for displaying full width pages.
*
* Template Name: ACF Front End Repeater Form
*
* @package storefront
*/
?>
<?php $post_id = 55; ?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
add_filter('acf/load_value/name=my_repeater_field','load_my_repeater_field_value', 10, 3);
function load_my_repeater_field_value($value, $post_id, $field) {
/*
--> adding the array() around get_post_meta() makes this output array match the default one (see line 57 below please), but it does not render form rows
$load_value = maybe_unserialize(get_post_meta($post_id, '_wc_booking_availability', true));
*/
$load_value = maybe_unserialize(get_post_meta($post_id, '_wc_booking_availability', true));
return $load_value;
/*
--> tried this, but it added extra empty rows somehow
return call_user_func_array('array_merge', $load_value);
*/
};
?>
<?php
$options = array(
'post_id' => $post_id,
'post_title' => true,
'field_groups' => array(
18,
),
'submit_value' => __("Update", 'acf'),
'updated_message' => __("Post updated", 'acf'),
'uploader' => 'wp'
);
?>
<?php acf_form($options); ?>
<?php
add_filter('acf/save_post', 'update_my_repeater_field_value', 20);
function update_my_repeater_field_value($post_id) {
// check the post type
// you don't want to do this on every post type
if (get_post_type($post_id) != 'product') {
return;
}
$value = get_field('my_repeater_field', $post_id);
update_post_meta($post_id, '_wc_booking_availability', $value);
} // when i submit the field, the ACF array (output below) deletes all the values
?>
<?php
// Printing both the pre-existing field and the ACF field arrays for debugging/testing
// ACF
$acf_repeater_array = get_field( "my_repeater_field", $post_id);
echo 'ACF repeater field array:<br><br>';
if( empty( $acf_repeater_array ) ){
echo '<strong>Empty</strong><br><br>';
} else {
print_r(array_values($acf_repeater_array)); // this doesn't match the array for the pre-existing field unless i wrap get_post_meta() in an array() on line 25
echo '<br><br><hr>';
};
// Pre-existing field
$pre_existing_array = get_post_meta( $post_id, '_wc_booking_availability' );
echo 'Pre-existing field array:<br><br>';
if( empty( $pre_existing_array ) ){
echo '<strong>Empty</strong><br><br>';
} else {
print_r(array_values($pre_existing_array));
echo '<br><br><hr>';
echo 'Pre-existing field array (when I \'flatten\' the pre-existing array):<br><br>';
$flat = call_user_func_array('array_merge', $pre_existing_array);
print_r(array_values($flat)); // this DOES match the array for the pre-existing field
echo '<br><br><hr>';
};
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
I’m at the point where I don’t know if I’m making progress or just getting more lost, so huge, huge thanks in advance for any insights!
It’s very simple standard search.php – i’m fairly certain it isn’t templating related but have a look – it’s built off of Bones WP :
<?php get_header('search'); ?>
<div id="content">
<div id="inner-content" class="wrap cf">
<main id="main" class="cf" role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Blog">
<!-- USER PANELS -->
<article class="cf" role="article" itemscope itemtype="http://schema.org/BlogPosting">
<section class="middlecontent cf" itemprop="articleBody">
<h3>Results:</h3>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$posts = get_field('author_selector');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<figure class="effect-marley m-all t-1of3 d-1of3">
<div class="thumbwrap">
<?php if ( get_the_post_thumbnail($post_id) != '' ) {
echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
the_post_thumbnail('sterling-largethumb');
echo '</a>';
} else {
echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
echo '<div class="fillthumb" style="background-image:url(';
echo catch_that_image();
echo ');"></div>';
echo '</a>';
} ?>
</div>
<figcaption>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">View more</a>
</figcaption>
</figure>
<?php endwhile; ?>
<?php wpex_pagination(); ?>
<?php else : ?>
<?php endif; ?>
</section>
</article>
</main>
</div>
</div>
<?php get_template_part( 'partials/socialmedia', '' ); ?>
<?php get_footer(); ?>
Of course I have acf_form() !
Here is the full code of this page :
<?php acf_form_head(); ?>
<?php get_header(); ?>
</script>
<div id="content">
<div id="inner-content" class="wrap cf">
<main id="main" class="m-all t-2of3 d-5of7 cf" role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Blog">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'cf' ); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
<header class="article-header">
<h1 class="page-title" itemprop="headline"><?php the_title(); ?></h1>
</header> <?php // end article header ?>
<section class="entry-content cf" itemprop="articleBody">
<?php
$options = array(
'field_groups' => array('group_54dcecbb2f254','group_54ddd77bb7f6b'),
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'post',
'post_status' => 'pending',
),
'submit_value' => __('Add this document', 'xxx'),
'updated_message' => __('Document added.','xxx'),
'uploader' => 'basic',
);
acf_form($options);
?>
</section>
</article>
<?php endwhile; endif; ?>
</main>
</div>
</div>
<?php get_footer(); ?>
This code works because I specify field_groups ; without this value, nothing appears but the submit button.
So, it’s totally impossible to display a group field (or, better, some fields into a group field) depending on a taxonomy field ? It’s very very awkward !
Hi,
Okay.. So first off. I don’t think this can be called an issue of ACF as it’s more about what WordPress consider is the current global post or query. What you want to do is basically nested custom queries.
Could you give this code a try? If you notice I do use $post for the foreach loop along with setup_postdata but instead of calling wp_reset_postdata() I call a function on the custom query itself to restore that in particular.
<?php $args = array(
'post_type' => 'corsi',
'posts_per_page' => 6
);
$the_query = new WP_Query( $args);
// The Loop
if ( $the_query->have_posts() ) : ?>
<div class="listing-corsi">
<div class="col-group-row">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col one-third m-1-2 s-1-1">
<div class="item-corso" data-mh="grp-item-corso">
<figure class="bwWrapper main-thumb"><?php the_post_thumbnail('t630x364');?></figure>
<div class="entry-content">
<h2 class="entry-title"><?php the_title();?></h2>
<div class="meta">
<div class="date"><?php the_field('data_corso');?> / <?php the_field('orario_corso');?></div>
</div><!--/.meta-->
<div class="entry-text">
<?php the_content();?>
</div><!--/.entry-text-->
<div class="show-related-ricette">
<span class="icon-top-arrow"></span> Ricette correlate al corso
</div><!--/.show-related-ricette-->
<?php
$posts = get_field('ricette_correlate');
if( $posts ): ?>
<div class="related-ricette">
<div class="close"><span class="icon-close"></span></div>
<ul>
<?php foreach( $posts as $post ): setup_postdata($post); ?>
<li>
<a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a>
</li>
<?php endforeach; $the_query->reset_postdata(); ?>
</ul>
</div><!--/.related-ricette-->
<?php endif; ?>
<div class="cat-list">
<?php
global $post;
$terms = wp_get_post_terms( $post->ID , 'tipologia_di_cucina' );
if ( $terms ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li><a href="'.get_term_link( $term ).'">' . $term->name . '</a></li>';
}
echo '</ul>';
}
?>
</div><!--/.cat-list-->
</div><!--/.entry-content-->
</div><!--/.item-corso-->
</div><!--/.col-->
<?php endwhile; ?>
</div><!--/.col-group-row-->
</div><!--/.listing-corsi-->
<?php endif; wp_reset_postdata(); ?>
<?php $posts=get_field( 'ricette_correlate'); if( $posts ): ?>
<div class="related-ricette">
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>">
<?php echo get_the_title( $p->ID ); ?></a>
</li>
<?php endforeach; ?> </ul>
</div>
<!--/.related-ricette-->
<?php endif; ?>
this is inside homepage (created with a custom page tpl, inside the post-type query).
Complete code of custom query:
<?php $args = array(
'post_type' => 'corsi',
'posts_per_page' => 6
);
$the_query = new WP_Query( $args);
// The Loop
if ( $the_query->have_posts() ) : ?>
<div class="listing-corsi">
<div class="col-group-row">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col one-third m-1-2 s-1-1">
<div class="item-corso" data-mh="grp-item-corso">
<figure class="bwWrapper main-thumb"><?php the_post_thumbnail('t630x364');?></figure>
<div class="entry-content">
<h2 class="entry-title"><?php the_title();?></h2>
<div class="meta">
<div class="date"><?php the_field('data_corso');?> / <?php the_field('orario_corso');?></div>
</div><!--/.meta-->
<div class="entry-text">
<?php the_content();?>
</div><!--/.entry-text-->
<div class="show-related-ricette">
<span class="icon-top-arrow"></span> Ricette correlate al corso
</div><!--/.show-related-ricette-->
<?php
$posts = get_field('ricette_correlate');
if( $posts ): ?>
<div class="related-ricette">
<div class="close"><span class="icon-close"></span></div>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div><!--/.related-ricette-->
<?php endif; ?>
<div class="cat-list">
<?php
global $post;
$terms = wp_get_post_terms( $post->ID , 'tipologia_di_cucina' );
if ( $terms ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li><a href="'.get_term_link( $term ).'">' . $term->name . '</a></li>';
}
echo '</ul>';
}
?>
</div><!--/.cat-list-->
</div><!--/.entry-content-->
</div><!--/.item-corso-->
</div><!--/.col-->
<?php endwhile; ?>
</div><!--/.col-group-row-->
</div><!--/.listing-corsi-->
<?php endif; wp_reset_postdata(); ?>
yep, its a custom theme and this is the part where i have to add the short_description custom field
<?php global $post, $swp_bread_status_blog, $swp_postmeta_status_blog,$swp_colsidemasonrywidth,$swp_colnosidemasonrywidth,$swp_colsidemasonrywidth_tablet, $swp_colnosidemasonrywidth_tablet, $swp_colspan, $swp_colspanmeta, $swp_leadingposts, $swp_leadingcolspan, $swp_post_wordlimit_blog, $swp_responsive; ?>
<?php dynamic_sidebar('sidebar-7'); ?>
<div class="post nocolsidepost"><div class="posttop"></div><div class="postinner-h1">
<h1><?php echo single_cat_title(); ?> günstig online kaufen!</h1>
</div></div>
<div id="masonthis">
<?php $swp_count=1; ?>
<div role="main" itemprop="mainContentOfPage">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_ts_colspan(); if ($swp_count <= $swp_leadingposts) {$swp_colspan = $swp_leadingcolspan;} else if ($swp_colspanmeta != "" ) {$swp_colspan = $swp_colspanmeta;} else {$swp_colspan = 1;} ?>
<?php get_theme_div( 'post', 'top', $sidebar, $cols ); ?>
<?php $wpaztemplate = get_post_meta($post->ID, 'wpaztemplate', true);
if ($wpaztemplate=="No Template" || $wpaztemplate=="") {
if ($swp_post_wordlimit_blog!='0'){ $teaser = true; } else { $teaser = false; } ?>
<article role="article" itemscope itemtype="http://schema.org/Article">
<?php get_theme_piece ( 'posttitle' ); ?>
<?php if ( $swp_postmeta_status_blog=="Show"){ get_theme_piece( 'postinfo' ); } ?>
<?php get_theme_piece( 'featuredimage' ); ?>
<div itemprop="articleBody"><?php if ($teaser){ echo teaser($swp_post_wordlimit_blog); } else { the_content(''); } ?></div>
<div class="clear"></div>
<?php get_theme_piece( 'postinfotwo', '', $swp_postmeta_status_blog, $teaser ); ?>
</article>
<?php } else {
$wpaz_word_count = get_theme_mod( 'wpaz_word_count_side', '250'); if ($wpaz_word_count!='' && $wpaz_word_count!=0){ $teaser = true; } else { $teaser = false; } ?>
<section role="article" itemscope itemtype="http://schema.org/Product">
<?php get_theme_piece ( 'posttitle' ); ?>
<?php get_custom_theme_piece( 'featuredimage', 'productblog', $sidebar, $swp_colspan ); ?>
<div class="proddesc" itemprop="description"><?php if ($teaser){ echo teaser($wpaz_word_count); } else { the_content(''); } ?></div>
<?php $wpaz_showstars = get_theme_mod( 'wpaz_showstars', 'No'); if ($wpaz_showstars=="Yes"){ ?><div class="reviewscorewrap"><?php get_custom_theme_piece( 'reviewscore' ); ?></div><?php } ?>
<?php get_custom_theme_piece( 'product-box', 'small' ); ?>
<div class="clear"></div>
</section>
<?php } ?>
<?php get_theme_div( 'post', 'bottom' ); ?>
<?php $swp_count++; endwhile; else: ?>
<?php get_theme_piece( '404content' ); ?>
<?php endif; ?>
</div>
</div>
<?php if ($cols == 'col') { ?>
<script type="text/javascript"><!--
jQuery(window).load(function(){
<?php if (!$swp_responsive) { ?>
jQuery('#masonthis').masonry({
columnWidth: <?php echo ${"swp_col".$sidebar."masonrywidth"}; ?>,
itemSelector: '.post'
});
<?php } else { ?>
fw = jQuery('.fullscreen').width();
if (fw > 960){
jQuery('#masonthis').masonry({
columnWidth: <?php echo ${"swp_col".$sidebar."masonrywidth"}; ?>,
itemSelector: '.post'
});
} else if (fw < 960 && fw > 751){
jQuery('#masonthis').masonry({
columnWidth: <?php echo ${"swp_col".$sidebar."masonrywidth_tablet"}; ?>,
itemSelector: '.post'
});
}
<?php } ?>
});
--></script>
<?php } ?>
<div class="clear"></div>
<?php get_theme_piece( 'blogtitle', '', $sidebar, 'nocol' ); ?>
<?php dynamic_sidebar('sidebar-8'); ?>
Actually that did not solve the problem. It seems anytime i put a relationship field in the header, page, sidebar, anywhere – anytime there is a wordpress default loop after that, that loop won’t run.
If i comment out this code in my header-news.php file, then the rest of the page will run just fine.
I have tried variations of this code too, but it doesnt seem to work.
Maybe if you can take a look you can spot something wrong with it.
<?php
$post_id = 19;
$headerqry = array(
'p' => $post_id,
'post_type' => 'any',
'posts_per_page' => 1,
'status' => 'published'
);
$loop = new WP_Query( $headerqry );
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
$posts = get_field('header_promo_banner');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<?php
$attachment_id = get_field('promo_image');
$size = "promo-header";
$image_attributes = wp_get_attachment_image_src( $attachment_id, $size );
if( $image_attributes ) {
?>
<a href="<?php echo the_field('promo_url'); ?>" target="_blank"><img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>"></a>
<?php } endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<?php endwhile; endif; wp_reset_query(); ?>
On most pages i am using global $post; $post_id = $post->ID; to get the ID of the current page outside of the loop.
I was hoping that wp_reset_query would reset the loop and let the items after this query run, but it doesnt seem to work.
Then the code in my single-10.php file is pretty basic:
while ( have_posts() ) : the_post(); ?>
<div class="main-photo-wrapper">
<img src="<?php echo the_field('header_photo'); ?>" style="width:100%; height:auto;" alt="<?php echo the_field('header_alt_text'); ?>"/>
</div>
<div class="title-bar">
<h2><?php the_title(); ?></h2>
</div>
<div class="article-content">
<?php the_content(); ?>
</div>
<?php endwhile; // end of the loop. ?>
So I tried submitting, waiting until it finished submitting, and then turned debug mode on. Here’s some of the errors I got:
Notice: Undefined offset: 0 in /home/onestopmods/public_html/wp-content/themes/osmMK2/template-editpost.php on line 22
Notice: Trying to get property of non-object in /home/onestopmods/public_html/wp-content/themes/osmMK2/template-editpost.php on line 22
Notice: Undefined variable: specicat in /home/onestopmods/public_html/wp-content/themes/osmMK2/template-editpost.php on line 31
and here’s the contents of my “editpost.php”:
<?php
/*
Template Name: Edit Post
*/
acf_form_head();
get_header();
$postide = $_GET['id'];
?>
<div id="main" class="full-width"><div class="wrap cf">
<div id="content" role="main">
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1 class="page-title">Editing Mod: <?php echo get_the_title("$postide"); ?></h1>
<div class="page-content rich-content">
<?php if ( current_user_can('edit_post', $postide) ) { ?>
<?php
$category = get_the_category("$postide");
$specat = $category[0]->cat_ID;
if($specat == 2){$namecat = Minecraft;}
?>
<?php
if($specat == 2){$specicat = 1193;}
acf_form(array(
'post_id' => "$postide",
'post_title' => true,
'post_content' => true,
'field_groups' => array( 1185, 1191, $specicat, 1197, 1200),
'submit_value' => 'Submit Changes',
'return' => 'http://onestopmods.com/view-mods/',
));
?>
<?php } else { echo 'You do not have permission to access this page. If you are not logged in, try logging in. If you believe that this is an error, please <a href="http://onestopmods.com/contact/">Contact Us.</a>';} ?>
</div>
</div><!--end .hentry-->
<?php endwhile; ?>
</div><!--end #content-->
</div></div><!-- end #main -->
<?php get_footer(); ?>
It says the variables are undefined, but I’m getting them through a query string in the URL. Is this not possible to fix?
I’d also like to note that these errors don’t show up when I initially load up the edit form. It only happens when I click submit and it redirects me to the same url, but with blank values everywhere. This error also doesn’t happen if there aren’t URLs (http://) in the fields.
Hmm… I enabled WP debug and I saw this appear repeatedly throughout the site:
Notice: is_main_query was called incorrectly. In pre_get_posts, use the WP_Query::is_main_query() method, not the is_main_query() function. See http://codex.wordpress.org/Function_Reference/is_main_query. Please see Debugging in WordPress for more information. (This message was added in version 3.7.) in /home/onestopmods/public_html/wp-includes/functions.php on line 3245
I deactivated the plugin, but I couldn’t access the site after that because of a get_field error (I assume this is normal if the plugin is deactivated) so I can’t really say if the plugin is the one causing this.
Also, if debug mode is on and if the plugin is enabled, I’m unable to even click “submit”.
Here’s the code for my “Add Post” page:
<?php
/*
Template Name: Add Post
*/
acf_form_head();
get_header();
$specat = $_GET['cat'];
if($specat == 2){$namecat = Minecraft;}
?>
<div id="main" class="full-width"><div class="wrap cf">
<div id="content" role="main">
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1 class="page-title">Submitting a Mod for: <?php echo $namecat; ?></h1>
<div class="page-content rich-content">
<?php
if($specat == 2){$specicat = 1193;}
acf_form(array(
'post_title' => true,
'post_content' => true,
'post_id' => 'new_post',
'new_post' => array(
'post_title' => 'New Post',
'post_type' => 'post',
'post_status' => 'pending',
'post_category' => array("$specat") ,
),
'field_groups' => array( 1185, 1191, $specicat, 1197, 1200),
'submit_value' => 'Submit Your Mod',
'return' => 'http://onestopmods.com/view-mods/',
)); ?>
</div>
</div><!--end .hentry-->
<?php endwhile; ?>
</div><!--end #content-->
</div></div><!-- end #main -->
<?php get_footer(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.