ACF Form with Polylang - duplicated form - wordpress

I am using this function to render form in frontend.
acf_form(['id' => 'onboarding',
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'onboarding_form',
'post_title' => "$current_user->user_email ($current_user->last_name $current_user->first_name)",
'post_status' => 'publish'),
'submit_value' => __('Save and continue', 'swp'),
'html_submit_button' => $submitBtnHtml,]);
It worked perfectly, but now I tried to translate it. And when I access the page with this form, the form is there in both languages, no matter which one is currently set.
It shows me the same forms together, first one is in English and second one is the translated one.
Did I set up something wrong in Polylang or in ACF?
Or is it possible to get form based on current language?
Thank you

Related

Woocommerce custom attributes not created, wc_create_attribute still working?

Is there something i am missing?
I try to create a new custom attribute for plugin purpose, but somehow it doesnt work.
The simple function is as follows:
$data = array(
'name' => 'programmas',
'slug' => 'elearning_programmas',
'type' => 'select',
'order_by' => 'menu_order',
'has_archives' => 1
);
wc_create_attribute( $data );
However, whatever i do, no new attribute is created in the list with attributes under the product attributes page, neither available on the individual product page.
Any ideas?

ACF Form not redirecting on Mobile. Working fine on desktop

I have a frontend acf form which is generating a new custom post.
When I submit the form on a desktop it works fine. It creates the post and redirects to the new post.
However when I use it on a mobile device, tested on Chrome, Firefox and Safari. The form creates the new post but doesn't redirect to the URL. Instead the spinning wheel gets stuck spinning and the page doesn't redirect anywhere.
The code I'm using is;
<!--ACF Frontend form-->
<?php
acf_form(array(
'post_id' => 'new_post',
'field_groups' => array(220), // Used ID of the field groups here.
'post_title' => false, // This will show the title filed
'post_content' => false, // This will show the content field
'form' => true,
'new_post' => array(
'post_type' => 'setup',
'post_status' => 'publish',
),
'return' => '%post_url%',
'submit_value' => 'Submit Setup',
));
?>

Wordpress get_pages meta_key don't show page

I'm using get_pages in a Wordpress theme to create the nav.
I have some pages I don't want to show in the nav.
On all pages I have a 'dont_show_in_nav' true/false custom field.
I can use meta_key to add pages that have 'dont_show_in_nav' selected
but I'd like to not show the pages that have 'dont_show_in_nav' selected.
I could create a 'show_in_nav' custom field and select all the pages to show but I have to many pages to do that.
I've tried 'meta_value' => false
$pages_args = array(
'sort_column' => 'menu_order',
'parent' => 0,
'post_type' => 'page',
'post_status' => 'publish',
'meta_key' => 'dont_show_in_nav',
'meta_value' => true
);
I'm guessing that the issue is that meta_value has to be a string since WordPress only supports strings for post meta. When you create your field, what are you actually saving? Is it the word "true", is it a '0', a '1' etc?
Regardless, a much better method for generating nav menus in wordpress is to take advantage of the nav menu functions. Take a look at wp_nav_menu(), that should work much more reliably than a meta key.
As of now Wordpress documentation for get_pages() says the function doesn't support querying with a meta_key:
NOTE: This function will currently not retrieve pages using the 'meta_key' and 'meta_value' parameters in the $args array as described below. Until this is fixed in the WordPress codebase, you may want to use get_posts() instead.
So your code should call get_posts() instead:
$pages_args = array(
'orderby' => 'menu_order',
'parent' => 0,
'post_type' => 'page',
'post_status' => 'publish',
'meta_key' => 'dont_show_in_nav',
'meta_value' => 'true'
);
$pages = get_posts($pages_args);
Note that I quoted 'true', since to Wordpress it's just a text field. Also, some arguments for get_posts are slightly different than for get_pages.

Wordpress: get_categories for custom post type with a specific custom taxonomy attached

Basically I have a custom post type of 'products' which has two taxonomies attached to it...the normal 'category' and a custom taxonomy called 'brands'.
I have a page which is 'brand' specific. On this page I'd like to list all the 'categories' that have a 'product' in them with a term of the 'brand' whos page I'm on attached.
Eg. say I'm on the "Nike" page. I want it to list all categories that have a 'product' in them with the 'brand' of "Nike" attached to them.
My initial thoughts are to use get_categories but theres now way to define a specific taxonomy or 'brand'?
$categories = get_categories('orderby=name&depth=1&hide_empty=0&child_of='.$cat);
Anyone done this before or knows a way to query the database directly to get the required results?
Any help is much appreicated, Thanks
I realize this is an older question, but in case anyone stumbles across this question while looking for an answer (as I did), get_categories() will now do this natively. Note the 'taxonomy' => 'taxonomy-type' in the $args array. Simply provide the registered taxonomy name to override the default value of category.
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false );
http://codex.wordpress.org/Function_Reference/get_categories
sorry about the delay. managed to sort it on the Wordpress stack exchange at the following link (for anyone who has the same issue): https://wordpress.stackexchange.com/questions/10998/get-categories-for-custom-post-type-with-a-specific-custom-taxonomy-attached
To my knowledge, you cant use the get_categories () function with "Custom Post Types" and "Custom Taxonomies".
On this site you can find a good tutorial in how to use "Custom Taxonomies"
http://net.tutsplus.com/tutorials/wordpress/introducing-wordpress-3-custom-taxonomies/.
Under the point "Displaying Taxonomy Classifications on Individual Pages" there would have to the solution for your problem.

drupal form textfield #default_value not working

I am working on a custom module with multi-page form on drupal 6.
I found that #default_value is not working when my '#type' => 'textfield'.
However, when '#type'=>'textarea', it displays correctly with the '#default_value' specified.
Basically, I wrote a FormFactory to return different form definition ($form) based on the post parameter received. Initially, it returns the display of directories list, user then selects from radio buttos until a specific directory contains a xml file, it will become edit form. The edit form will have text fields display the data (#default_value) inside the xml file, however the type 'textarea' works here rather than 'textfield'.
How can I make my '#default_value' work in this case?
Below is the non-working field definition:
$form['pageset']['newsTitle'] = array(
'#type' => 'textfield',
'#title' => 'News Title',
'#default_value' => "{$element->newsTitle}",
'#rows' => 1,
'#required' => TRUE,
);
Then I changed it to textarea as shown below to make it work:
$form['pageset']['newsTitle'] = array(
'#type' => 'textarea',
'#title' => 'News Title',
'#default_value' => "{$element->newsTitle}",
'#rows' => 1,
'#required' => TRUE,
);
There should be no difference between a textfield and a textarea form element concerning the usage of the '#default_value' attribute, and both work for me as advertised. So if it does not work in your case, you should check for typos or other differences that might cause the faulty behavior.
Could you edit your question and add your form definition code?
What Drupal versions are you on? I'm on 6.16 and I'm having weird behaviour for defaults too. In my case, not working for textareas.
I'm a non-english speaker and my default_value had non ascii characters. It's fixed now using translation.

Resources