Show data of a Post Object field in the an ACF Group - wordpress

I created a custom field group named "Agenda 2" using Advanced Custom Field plugin in Wordpress. Under the group, I created a Post Object field named Panelist Chair. I can't seem to pull the data in the sub field named "Panelist Chair". But I can able to pull the data from another Post Object field I created outside the group.
$thegroupfield = get_field('agenda_2');
print_r($thegroupfield); //this returns all the arrays which is fine
$pchair = get_field('panelist_chair');
print_r($pchair); //this doesn't return any value
$pchair = get_sub_field('panelist_chair');
print_r($pchair); //this doesn't return any value too
$mod = get_field('moderator'); //another post object field outside the group
print_r($mod); //this returns array which is fine
How can I get to show the data of the post object field in the group?

Have you tried the following? The field panelist_chair is part of your agenda_2 field. You can t acces it with a get_field function because it is inside the array of agenda_2.
$thegroupfield = get_field('agenda_2');
print_r($thegroupfield['panelist_chair'])

Related

Does WordPress avoids arrays on wp_insert_post_data filter?

I'm using wp_insert_post_data filter hook to save some extra data which I get from a meta box in a custom post type. I want to save these extra data as the post_content not the post_meta_data.
There is a select box with Select2 which is possible to select more than one values (pillbox). Finally Select2 prepares an array of values. I've checked browser Network section and the value is an array but when I try to access the value in wp_insert_post_data, I just get the last item of the array as an string and not an array!
Here is my function :
function xxx_save_country_data(array $data): array
{
$countries = $_POST['xxx_countries_field']; //It should be an array but it is only string
return $data;
}
add_filter('wp_insert_post_data', 'xxx_save_country_data');
Posted data screenshot: https://i.stack.imgur.com/0kX97.png
In my plugin case, I'm using woocommerce_form_field to generate the select element and if you don't specify id parameter as the $args in this function, both id and name properties get the same string and so it becomes xxx_countries_field and not xxx_countries_field[] which was the problem!

Akeneo: Create a new variant group with attributes

I want to create a new variant group in Akeneo with some fixed attributes to "simulate" the behaviour of a product family. Unfortunately I don't know how to get a ProductTemplate with some attributes with empty values.
When I tried my code below, I get an error after opening the created variant group in the Akeneo GUI:
Error: Option "attributes" must only contains instances of "Pim\Bundle\CatalogBundle\Entity\Attribute", got "Pim\Bundle\EnrichBundle\Form\Type\AvailableAttributesType"
My code looks like this:
$groupType = $this->groupManager
->getGroupTypeRepository()
->findOneBy(['code' => 'VARIANT']);
$group = $this->groupFactory->createGroup($groupType);
$group->setCode('MY_VARIANT_GROUP');
$attributes = array($this->attributeRepository->findOneByIdentifier('AXIS_ATTRIBUTE'));
$group->setAxisAttributes($attributes);
// ??? How can I create a new product value?
$productValue1 = new ProductValue();
$productValue1->setId('PREDEFINED_ATTRIBUTE1');
$productValue1->setAttribute($this->attributeRepository->findOneByIdentifier('PREDEFINED_ATTRIBUTE1'));
$productTemplate = new ProductTemplate();
$productTemplate->setValuesData(array($productValue1));
$group->setProductTemplate($productTemplate);
$this->groupSaver->save($group);
I advise you to use the Pim\Bundle\CatalogBundle\Builder\ProductTemplateBuilder to create and add attributes to your product template.
This will ensure that the product template will be properly created with empty product values.

Show up Woocommerce custom fileds into the CSV export

I'm using "Woocommerce CSV Export" plugin and i've just added 2 custom fileds into my WC checkout page, I was wondering if i can add those fileds to the export plugin.
Just add the following code into your "woocommerce-export-csv.php"
add_filter( 'woocommerce_export_csv_extra_columns', 'sites_add_custom_meta', 10);
and the define your function
function sites_add_custom_meta() {
$custom_meta_fields['columns'][] = 'IP Address';
$custom_meta_fields['data'][] = '_customer_ip_address';
return $custom_meta_fields;
}
In this function you have two things you need to define. First, in the columns array you need to define the titles of your custom meta fields and then in the data array you need to define actual meta field name where the data for that field is located at. You need to have the same order in both arrays to be able to have correct information output under right column title.
Source : http://docs.woothemes.com/document/ordercustomer-csv-exporter/#section-4

Fetcing dynamically added fields in forms - Symfony2

i have some data that will be added in hidden input fields inside a form.
Now since i'm using symfony2 forms those fields don't get submitted.
i.e. $form->getData() does not get data from those fields.
how do i get data from those dynamically added (hidden) input fields as well?
Fetch post values in context of a form type:
$postData = $request->request->get('form_name');
$name_value = $postData['title'];
Fetch post values not in context of a form type (maybe this is what you need):
$data = $request->request->all();
$name = $data['input_name'];

How could I have a cck field get the computed value of another cck field?

Lets say I have a cck field called foo. It is a text field with php input. Say the php code in foo field results in the value of 1,256 when computed. I need cck field called bar to pick up/obtain/have the VALUE (1,256) of cck field foo.
Node XYZ
Foo:*some php code* ===>results in value of 1,256
Bar:1,256
If I just have cck field Foo in a node, it spits out the correct value, (1,256) but that field is the way our views are sorted; and views cant sort by a php field.
I tried to get computed_field.module to obtain its value, but it would spit out the php code, not the value.
Any ideas out there?
You need to hook the node submit form, and add a submit handler
function moduleNameHere_form_nodeNameHere_node_form_alter(&$form, $form_state) {
//Add handler
$form['#submit'][] = 'moduleNameHere_submit_function';
}
then you create the handler that will get called on submit
function moduleNameHere_submit_function($form, &$form_state) {
//Assign foo's value to variable
$myValue = $form_state['values']['foo'];
//Set bar to foo's variable
$form_state['values']['bar'] = $myValue;
}

Resources