Advanced Custom Fields Not Displaying on Desired Page - php

I'm using the Advanced Custom Field (ACF) Plugin for my Wordpress blogs. Each blog has the same general heading/logo to the page.
Immigration Law
Health Law
The two elements that generally change are the standard colors associated with the blog's name and the name of the blog (i.e. Health vs Immigration).
I've added a few ACF fields into a new group (blog_type, blog_name, blog_color) and inserted them into the header.php file where I want them. I've also assigned them to the following location rules:
User, is equal to, Administrator (and)
Page, is equal to, Home
When I choose Update and proceed to the home page, the new fields should be there but are not.
I did a little digging and found that I needed to add the exported info that it generates to my functions.php page in my child theme. But when I do that and go back to my Group details in the plugin menu, all but one of the fields are gone.
Not sure what I'm doing wrong.
Wordpress version: 4.2.2
Parent Theme: Elegant Themes - Divi (version 2.3.1)
ACF Plugin Version: 4.4.2
EDIT:
Here's the code I added to my header.php
<h1>
knowing<span style="color: <?php the_field('blog_color');?>;"><?php the_field('blog_name');?></span><?php the_field('blog_type');?>
</h1>
This is the code that the export function gave me for my functions.php file:
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_blog-details',
'title' => 'Blog Details',
'fields' => array (
array (
'key' => 'field_55a40afe0bf59',
'label' => 'Blog Color',
'name' => 'blog_color',
'type' => 'color_picker',
'required' => 1,
'default_value' => 'rgb(210,120,40)',
),
array (
'key' => 'field_55a41857b2d0f',
'label' => 'Blog Name',
'name' => 'blog_name',
'type' => 'text',
'required' => 1,
'default_value' => 'Blog',
'placeholder' => 'Blog Name',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a41859b2d10',
'label' => 'Blog Type',
'name' => 'blog_type',
'type' => 'radio',
'instructions' => 'Choose a type of Blog',
'required' => 1,
'choices' => array (
'blog' => 'blog',
'relations' => 'relations',
),
'other_choice' => 0,
'save_other_choice' => 0,
'default_value' => '',
'layout' => 'vertical',
),
),
'location' => array (
array (
array (
'param' => 'ef_user',
'operator' => '==',
'value' => 'administrator',
'order_no' => 0,
'group_no' => 0,
),
array (
'param' => 'page',
'operator' => '==',
'value' => '23',
'order_no' => 1,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
0 => 'custom_fields',
),
),
'menu_order' => 0,
));
}
EDIT 2:
Okay I found something strange out, when I removed the User = Admin out from the Location Rules, it showed up. But I only want Admins to see that. Not sure what to do.

Related

add acf filed to admin_menu programmatically

can we add ACF fields to custom admin_menu page?
so I have created an admin page as shown
add_action( 'admin_menu', 'opt_add_admin_menu' );
function opt_add_admin_menu( ) {
add_menu_page( 'opt', 'opt', 'manage_options', 'opt', 'opt_options_page' );
}
so next I need to add an ACF field to this options page
I got this code from ACF but the location still makes a problem for me
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6335ef4ab316e',
'title' => 'justfortest',
'fields' => array(
array(
'key' => 'field_6335ef5351c1c',
'label' => 'text',
'name' => 'text',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
'location' => array(
array(
array(
'param' => 'post_type', /* here we need to target the menu options page */
'operator' => '==',
'value' => 'post', /* here to */
),
),
),
I know how to add fields programmatically without ACF but if there is a way to add through ACF it will be so helpful
Create new admin page using acf option page
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'opt',
'menu_title' => 'opt',
'menu_slug' => 'opt-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
and select option page ->opt while adding new group
--- You need acf pro version to use this feature

Advanced Custom Fields plugin User dropdown is not working

I am using the ACF plugin in one of the WordPress websites and I have the following configuration for a user dropdown. This is added as a PHP code.
acf_add_local_field_group(array (
'key' => 'group_557ad1ef2b8a1',
'title' => 'Authors',
'fields' => array (
array (
'key' => 'field_557ad24ba99e5',
'label' => 'Featured',
'name' => 'featured_authors',
'type' => 'repeater',
'instructions' => 'Choose a maximum of 6 authors',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'min' => '',
'max' => 6,
'layout' => 'table',
'button_label' => 'Add Author',
'sub_fields' => array (
array (
'key' => 'field_5582bc82f8419',
'label' => 'Author',
'name' => 'featured_authors_author',
'type' => 'user',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'role' => '',
'allow_null' => 0,
'multiple' => 0,
),
),
)
'menu_order' => 0,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => array (
0 => 'the_content',
1 => 'author',
2 => 'featured_image',
),
));
Now from the admin section, I am trying to add this field to the page, but it is not permitting the admin to select users. The dropdown is showing without any values. I am using the following versions:
Wordpress - 5.7.3
Advanced Custom Fields - 5.4.5
You have a syntax error in your code. You didn't close the first array() inside the 'fields' parameter in your main list of fields. Before this line:
'menu_order' => 0,
you need to add this:
),
This will close the 'fields' parameter, and allow it to process the parameters that appear after it.
I ended up recreating your field group in the ACF User Interface in the WP Admin, then exported the php, stripped out all the unnecessary/default parameters, and it's working great for me on a test environment. See the code below. I stripped out all of the settings that were just set to the default settings, to help make things a bit more readable.
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6148d6a5d8172',
'title' => 'Authors',
'fields' => array(
array(
'key' => 'field_6148d6afde7ec',
'label' => 'Featured',
'name' => 'featured_authors',
'type' => 'repeater',
'instructions' => 'Choose a maximum of 6 authors',
'max' => 6,
'button_label' => 'Add Author',
'sub_fields' => array(
array(
'key' => 'field_6148d6d5de7ed',
'label' => 'Author',
'name' => 'featured_authors_author',
'type' => 'user',
'required' => 1,
),
),
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'style' => 'seamless',
'hide_on_screen' => array(
0 => 'the_content',
1 => 'author',
2 => 'featured_image',
),
));
endif;
One thing I noticed is that your code doesn't have any Location settings to dictate what post type or other element the field group should appear on, so I set my example to appear on every Post. You may need to adjust this to match your needs.
I also included the if function_exists conditional wrapper so that if you turn off the ACF plugin, it won't generate errors when it cannot find the acf_add_local_field_group() function.

Losing line breaks in Wordpress + q-translate + CMB2 + repeatable group

I'll try to be short:
Multilingual Wordpress site with custom post type registered in functions.php and CMB2 for creating custom forms. The plugin for multilingual is q-translate-x and also using CMB2-qTranslate.
My problem is that I'm losing all line breaks and all <p> tags when I switch the language but it only fails if the editor is contained in a repeatable group. If I add the wysiwyg edit as normal field It works fine.
-Relevant code for the normal field (this works fine):
$cmb_tb->add_field( array(
'name' => esc_html__( 'Historia', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'historia',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, 'editor_class' => 'cmb2-qtranslate'),
) );
-Relevant code for repeatable field (this loses line breaks and <p> tags on language switching):
<pre><code>
$group_field_id = $cmb_tb->add_field( array(
'id' => 'Fincas',
'type' => 'group',
'description' => __( 'Fincas', 'cmb2' ),
// 'repeatable' => false, // use false if you want non-repeatable group
'options' => array(
'group_title' => __( 'Finca {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __( 'AƱadir otra Finca', 'cmb2' ),
'remove_button' => __( 'Eliminar Finca', 'cmb2' ),
// 'sortable' => true, // beta
'closed' => false, // true to have the groups closed by default
),
) );
$cmb_tb->add_group_field($group_field_id, array(
'name' => esc_html__( 'Nombre Finca', 'cmb2' ),
'desc' => esc_html__( '', 'cmb2' ),
'id' => $prefix . 'nombre_finca',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, 'editor_class' => 'cmb2-qtranslate')
) );
</code></pre>
This is driving me crazy. I've created a sample website with this problem for testing. I can give access to anyone who feels that can help.
Many thanks in advance.
Finally, I figured out.
It was as easy to add 'wpautop' => false to options array

How to create dynamic fields in visual composer?

I am creating visual composer plugin for price table. I want to add dynamic textfield so user become able to add multiple text fields for item list as want.
For now it's showing only one text field but user should able to add multiple fields.
array (
"type" => "textfield",
"heading" => __( 'List Items', 'pt-vc' ),
"param_name" => "price_list",
"description" => __( 'Write the list item that you offer', 'pt-vc' ),
"group" => 'List Item',
),
You can use param_group. Here is the code example.
'params'=> array (
array(
'type' => 'param_group',
'value' => '',
'heading' => __( 'List Items', 'pt-vc' ),
'param_name' => 'price_list',
// Note params is mapped inside param-group:
'params' => array(
array(
'type' => 'textfield',
'value' => '',
'heading' => __( 'List Items', 'pt-vc' ),
'param_name' => 'list_itmes',
)
)
)
);
I think answer may be late but help others.
You may use param_group for that. It's not mentioned in the documentation but you may find it "How To's"
https://kb.wpbakery.com/docs/developers-how-tos/use-param-group-in-elements/
Code snippet from link (in case link expires again):
vc_map(
array(
'base' => 'your_shortcode',
'params' => array(
array(
'type' => 'textfield',
'value' => '',
'heading' => 'Title',
'param_name' => 'simple_textfield',
),
// params group
array(
'type' => 'param_group',
'value' => '',
'param_name' => 'titles',
// Note params is mapped inside param-group:
'params' => array(
array(
'type' => 'textfield',
'value' => '',
'heading' => 'Enter your title(multiple field)',
'param_name' => 'title',
)
)
)
)
)
)

Backend list records TYPO3 extension

I'm trying to create my first TYPO3 extension, with backend list records.
Now I can register my own list records, but they are registert under tt_news like this:
News
News
News cat
Inventory
Of course I want to make my extension have it's own parent category like tt_news has.
News
News
News cat
Inventoy
inventory item
Does anybody have experience with this?
My ext_tables.php so far:
<?php
if (!defined ('TYPO3_MODE')) die ('Access denied.');
$TCA['tx_inventory_domain_model_product'] = array (
'ctrl' => array (
'title' => 'Inventory',
'label' => 'name',
),
'columns' => array(
'name' => array(
'label' => 'Item Label',
'config' => array(
'type' => 'input',
'size' => '20',
'eval' => 'trim,required'
)
),
'description' => array(
'label' => 'Item Description',
'config' => array(
'type' => 'text',
'eval' => 'trim'
)
),
'quantity' => array(
'label' => 'Stock Quantity',
'config' => array(
'type' => 'input',
'size' => '4',
'eval'=> 'int'
)
),
),
'types' => array(
'0' => array('showitem' => 'name, description, quantity')
)
);
?>

Categories