Hi
There are a few variables here that could change the possible solutions.
But have you checked the Page ID ( Post ID ). I see you use the global $post variable. The ID can be changed by Plugins and Themes during the “PHP page compiling process”. Maybe you can “hardcode” to test if everything is working fine. The Page ID you need can be found when editing the page in the backoffice ( WP Admin ).
E.g. When editing a page you get the URL https://www.mywebsite.com/wp-admin/post.php?post=71 => 71 is the Post ID you need to pass in get_field( ‘mycustomfield’, 71 );
If this works, you need to rethink the global $post; $post->ID logic… Something is changing it before you can use it.
Hope this helps.
Kind regards
Matt
You need to add the post_id and new_post param to the $settings array.
Plz replace ‘your-cpt’ with the name of your custom post type.
$settings = array(
'id' => 'photos_form',
'post_id' => 'new_post',
'new_post' => [
'post_type' => 'your-cpt',
'post_status' => 'draft',
],
'field_groups' => array("group_6025117548b3f"),
'fields' => false,
'submit_value' => __("Submit", 'acf'),
'label_placement' => 'top',
'html_submit_button' => '<input type="submit" id="submitbtn" class="acf-button button primary_btn" value="%s" />',
'html_submit_spinner' => '<span class="acf-spinner"></span>',
'updated_message' => '',
'html_after_fields' => '',
);
@jochem You shouldn’t apply logic while building an array.
You might try:
$layouts = array();
if( in_array( 'service', $cpt_selection ) ) {
$layouts[] = array(
'id' => '',
'key' => '',
'
);
}
acf_add_local_field_group( array(
'key' => 'unique-key',
'title' => __('Content', 'textdomain'),
'fields' => array(
array(
'key' => 'unique-key',
'label' => __('Content', 'textdomain'),
'name' => 'field-name',
'type' => 'flexible_content',
'button_label' => __( 'Add content', 'textdomain' ),
'layouts' => $layouts,
)
),
'location' => array(),
'menu_order' => 10,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => ''
) );
Hope this helps
Kind regards
@johnw6761 I use a true/false field as enable/disable lightbox / fancybox field. This is no “simple solution” as in “plug-and-play” to implement. You need to register / enqueue the lightbox / fancybox css and js files yourself. Just wrap every image in your gallery loop with an element and the lightbox / fancybox options. If you want a plug-and-play solution, you’re gonna have to search for a plugin or add-on.
If you like to code, it could look something like this:
$output = '<figure' . get_the_attributes($attributes) . '>';
if(is_object($lightbox)) $output .= "<a data-fancybox=\"{$lightbox->id}\" href=\"{$lightbox->href}\" data-srcset=\"{$lightbox->srcset}\">";
if(!empty($options['before'])) $output .= $options['before'];
$output .= wp_get_attachment_image($image_id, $image_size, $is_icon, array('class' => $image_style));
if(!empty($options['after'])) $output .= $options['after'];
if(is_object($lightbox)) $output .= get_the_icon('search') . '</a>';
$output .= '</figure>';
Hope this helps.
Note “get_the_attributes” and “get_the_icon” are not default WP functions.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.