So i’m trying to create a link to a woocommerce product category. In my template i have this.
<a href="<?php echo get_term_link( get_field( ‘featured_page_link’ ) ); ?>">this is a test link</a>
I have added a taxonomy field for it with category (product_cat) selected. I have selected a cat on the page via the checkbox.
However it just breaks the template at the point where the link is and ignores the rest of the page.
I assume i am not using product category links correctly. Please help.
Thanks
Hi,
I’m wondering if after having created a group of fields assigned to a custom post type, it
is possible to only target a taxonomy of this custom post type with a field?
For exemple :
– Custom post type = “members” with two sub-categories (‘A’ and ‘B’)
– Group of fields with ‘position’ and ‘gender’
Is it possible to make the field ‘position’ only visible for ‘A’ categorized members when editing the CPT?
Hello, I am trying to display a simple list of custom taxonomies in my post via shortcode, but I get this warning:
ltrim() expects parameter 1 to be string, object given…
In the backend i created an ACF form with Taxonomy field; main settings:
name: custom_tax_fieldname
appearance: checkboxes
save terms: yes
return value: term object
In my php I added this code, borrowed and adapted from the documentation: https://www.advancedcustomfields.com/resources/taxonomy/
$custom_taxonomies = get_field('custom_tax_fieldname');
if( $custom_taxonomies ) {
foreach( $custom_taxonomies as $custom_taxonomy ){
echo "<a href='" . esc_url( get_term_link( $custom_taxonomy ) ) . "'>" . esc_html( $custom_taxonomy->name ) . "</a>";
if (next( $custom_taxonomies )) {echo ', ';}
}
}
but I get this warning multiple times (one for every taxonomy I am supposed to see): Warning: ltrim() expects parameter 1 to be string, object given in home/wp-includes/formatting.php on line 4309
I don’t know what am I doing wrong, can someone help?
Thank you very much in advance
I have created a custom post type called “Researchers”. There is a custom taxonomy field named “modeling types” which I’m using multi-select. At first I was only able to display the taxonomy ID. I got some help in re-writing the code to display the taxonomy name(s). But the field now returns “Uncategorized”. Can someone look at my code and tell me what I’m doing wrong. I’m new to php.
Modeling Type: <?php $modelingType = get_field('modeling_types'); $term = get_term($modelingType); echo esc_html($term->name); ?>
The output looks like this:
Modeling Type: Uncategorized
Also, the return value is set to Term ID. However when I set it to Term Object, the Modeling Type: Uncategorized doesn’t show at all.
Thank you for any assistance.
I am stuck and could use some advice. At work we created a list of living communities. I have been asked to organize them by location taxonomy (North,South,East,West). Currently we use the following code to display a list of the communities. This works fine.
<ul>
<?php
$i = 1;
while(has_sub_field('communities')):
echo '<li><a href="' . get_permalink() . '#community-' . $i . '">' . get_sub_field('community_name') . '</a></li>' ;
$i++;
endwhile;
?>
</ul>
I created a taxonomy (‘community_location’) that uses the categories of the different locations. We are looking to organize the list this way:
North
South
East
West
Any thoughts?
Hi, I want to have all my woo commerce product categories coming through on the back end of a post so that the user can choose the relevant product categories. Then on the front end I want to show the product categories that have been checked.
I have set my checkbox up as a Field type of taxonomy and appearance as “check box”. With the Taxonomy pointing to the relevant product category and return value set to “Term Object”. This all comes through the back end as expected.
Using <?php the_field('my_field_name'); ?>
I get all the info back of every category empty or not, but I can’t see a way of knowing if the field is checked or not. Am I able to check if the box is “checked” so that I only show the boxes which were checked names on the front end?
Any help appreciated.
Hello,
I am wondering how to display WooCommerce random 6-7 products from specific category on front-page.php by checking it in WordPress Page Editor.
I made a new type field – Taxonomy and choose Taxonomy – Category (product_cat).
1. Should I choose Return Value: Object (WP_Term) or ID ?
2. After step 1 is there any other way to display a products from choosen category than WP_QUERY? I need to display 3-4 categories (each in new row/section on page) and 6-7 products from each category.
Why doesn’t some PHP function call shown in the backend preview? (Some do)
I then noticed that while some PHP function works on the front-end and show proper results, but in the preview of the block, some doesn’t show the value that was returned from the function call. For example:
<?php echo get_the_title(); ?>
<?php echo get_the_post_thumbnail_url( null, 'full' ); ?>
These PHP calls doesn’t show anything in preview. But works in frontend.
But when I use another PHP to echo the custom taxonomy it is shown in the preview properly. The code is given below:
<?php foreach((get_terms('character_rarity')) as $terms) { echo $terms->name; }; ?>
So why is this happening? My main goal of creating the post is to know that. It’s not technically creating much of a trouble. As it is working in the front end as it was supposed to. But it is kind of decreasing the efficiency for the purpose of the preview option. So mainly would like to know why it’s happening and if it is possible to avoid it somehow.
Hello,
I have a flexible content field, and I have a layout that is a ‘taxonomy’ field, where the user can select Custom Post Type Categories to display on the front-end.
I have managed to pull the link and category image, however it doesn’t seem to pull the category name or description. When I var_dump()
these, they return NULL
.
Here is my code:
<?php // portfolio categories block
if( get_row_layout() == 'portfolio_categories_layout' ):
?>
<section class="portfolio-categories">
<?php
$terms = get_sub_field('portfolio_categories_layout_select');
if( $terms ):
?>
<ul class="category-list">
<?php foreach( $terms as $term ): ?>
<li class="category-item">
<div class="image" style="background-image: url('<?php echo z_taxonomy_image_url($term); ?>');"></div>
<div class="overlay"></div>
<div class="content">
<h2><?php echo esc_html( $term->name ); ?></h2>
<?php var_dump($term->name); ?>
<?php echo esc_html( $term->description ); ?>
<?php var_dump($term->description); ?>
<a class="button button-primary" href="<?php echo esc_url( get_term_link( $term ) ); ?>">View all '<?php echo esc_html( $term->name ); ?>' posts</a>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
<?php endif; ?>
Hi, I’m trying to add an accordion to this custom page builder but i cant get it to work. Basically i have added open and closing accordion fields to the json file and each has a title and a wysiwyg editor, but it breaks my site when i try to use it.
json code:
[
{
"key": "group_553b8b2752aba",
"title": "Page Builder",
"fields": [
{
"key": "field_553b8b4fc8c3b",
"label": "Page Sections",
"name": "acf_page_builder",
"type": "flexible_content",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"button_label": "Add Section",
"min": "",
"max": "",
"layouts": [
{
"key": "56c0e6afec566",
"name": "banner",
"label": "Banner Image",
"display": "block",
"sub_fields": [
{
"key": "field_56c0e6efec56d",
"label": "Contained",
"name": "contained",
"type": "true_false",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_56c0a959e8e90",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "Place in a container?",
"default_value": 0
},
{
"key": "field_56c0e712ec56e",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_56c0e6efec56d",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_56c0e6c8ec56c",
"label": "Image",
"name": "image",
"type": "image",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"return_format": "url",
"preview_size": "medium",
"library": "all",
"min_width": "",
"min_height": "",
"min_size": "",
"max_width": "",
"max_height": "",
"max_size": "",
"mime_types": ""
},
{
"key": "field_56c0f2dcf1e39",
"label": "Text",
"name": "use_text",
"type": "true_false",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "Place text over image?",
"default_value": 0
},
{
"key": "field_56c0f2b0f1e38",
"label": "Text on Top of Image",
"name": "text_on_image",
"type": "wysiwyg",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_56c0f2dcf1e39",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"tabs": "all",
"toolbar": "full",
"media_upload": 0
}
],
"min": "",
"max": ""
},
{
"key": "554a765bd3324",
"name": "button",
"label": "Button",
"display": "row",
"sub_fields": [
{
"key": "field_554a777fd3328",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_554a7667d3325",
"label": "Button Text",
"name": "button_text",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_554a7684d3326",
"label": "Page Linking",
"name": "link_to_page",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"anchor": "ID Anchor",
"external": "External Link",
"internal": "Internal Link"
},
"default_value": [],
"allow_null": 0,
"multiple": 0,
"ui": 0,
"ajax": 0,
"placeholder": "",
"disabled": 0,
"readonly": 0
},
{
"key": "field_55aff9e1ee51e",
"label": "Anchor",
"name": "button_anchor",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_554a7684d3326",
"operator": "==",
"value": "anchor"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "#",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_554a77f8d332b",
"label": "External Link",
"name": "external_link",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_554a7684d3326",
"operator": "==",
"value": "external"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_554a77c9d332a",
"label": "Internal Link",
"name": "internal_link",
"type": "page_link",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_554a7684d3326",
"operator": "==",
"value": "internal"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [],
"taxonomy": [],
"allow_null": 0,
"multiple": 0
}
],
"min": "",
"max": ""
},
{
"key": "5540bf0259b1d",
"name": "content_grid",
"label": "Content Columns",
"display": "block",
"sub_fields": [
{
"key": "field_56c0b470864df",
"label": "IMPORTANT",
"name": "",
"type": "message",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "<p style=\"color: red;\">This section uses <a href=\"http:\/\/getbootstrap.com\/\" target=\"_blank\">Bootstrap<\/a> columns. Bootstrap divides the page width by columns in divisions of 12. So for 2 columns use width col-sm-6, for 3 columns use width col-sm-4, and so on. In most cases 'Offset' should be set to 0.<\/p>",
"new_lines": "wpautop",
"esc_html": 0
},
{
"key": "field_554909228473a",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_56c0b485864e0",
"label": "Wrapper Class",
"name": "wrapper_class",
"type": "text",
"instructions": "i.e. col-sm-4 col-sm-offset-4",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_5540bf1159b1e",
"label": "Content Columns",
"name": "content_columns",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 1,
"max": 4,
"layout": "table",
"button_label": "Add Columns",
"sub_fields": [
{
"key": "field_5540c0bb59b1f",
"label": "Content",
"name": "content",
"type": "wysiwyg",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": 70,
"class": "",
"id": ""
},
"default_value": "",
"tabs": "all",
"toolbar": "full",
"media_upload": 1
},
{
"key": "field_554a5878c9372",
"label": "Width",
"name": "width",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": 15,
"class": "",
"id": ""
},
"default_value": 3,
"placeholder": "",
"prepend": "col-sm-",
"append": "",
"min": 1,
"max": 12,
"step": 1,
"readonly": 0,
"disabled": 0
},
{
"key": "field_554a57bbc9370",
"label": "Offset",
"name": "offset",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": 15,
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "col-sm-offset-",
"append": "",
"min": 0,
"max": 12,
"step": 1,
"readonly": 0,
"disabled": 0
}
]
}
],
"min": "",
"max": ""
},
{
"key": "553b90972ce3e",
"name": "gallery",
"label": "Gallery",
"display": "row",
"sub_fields": [
{
"key": "field_553bd89149bd2",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_56c0ef638f980",
"label": "Images per Row",
"name": "images_per_row",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": 4,
"placeholder": "",
"prepend": "",
"append": "",
"min": 2,
"max": 6,
"step": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_553b90972ce3f",
"label": "Images",
"name": "images",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 1,
"max": 8,
"layout": "table",
"button_label": "Add Image",
"sub_fields": [
{
"key": "field_553bd41f82d1e",
"label": "Image",
"name": "image",
"type": "image",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"return_format": "url",
"preview_size": "thumbnail",
"library": "all",
"min_width": "",
"min_height": "",
"min_size": "",
"max_width": "",
"max_height": "",
"max_size": "",
"mime_types": ""
},
{
"key": "field_553bd45b82d1f",
"label": "Title",
"name": "title",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_553bd48582d20",
"label": "Caption",
"name": "caption",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
}
]
}
],
"min": "",
"max": ""
},
{
"key": "561538dcc6acb",
"name": "raw_html",
"label": "Raw HTML",
"display": "row",
"sub_fields": [
{
"key": "field_56c0eb7227216",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_561538e6c6acc",
"label": "HTML",
"name": "html",
"type": "textarea",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"maxlength": "",
"rows": "",
"new_lines": "",
"readonly": 0,
"disabled": 0
}
],
"min": "",
"max": ""
},
{
"key": "561538dcw4334t",
"name": "accordion_row",
"label": "Accordion Row",
"display": "block",
"sub_fields": [
{
"key": "field_56c0ebgdtgs",
"label": "accordion-open",
"name": "",
"type": "accordion",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"open": 0,
"multi_expand": 0,
"endpoint": 0,
},
{
"key": "field_56c0eb72strgd",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_553bd45b2twf",
"label": "Title",
"name": "accordion-title",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_553b8ce8yb45rty",
"label": "Content",
"name": "content",
"type": "wysiwyg",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"tabs": "all",
"toolbar": "full",
"media_upload": 1
},
{
"key": "field_56c0ebgdwc3f5",
"label": "accordion-close",
"name": "",
"type": "accordion",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"open": 0,
"multi_expand": 0,
"endpoint": 1,
},
],
"min": "",
"max": ""
},
{
"key": "553b8cd6dbe66",
"name": "wysiwyg",
"label": "Content Editor",
"display": "block",
"sub_fields": [
{
"key": "field_553bc590fbc55",
"label": "Background Colour",
"name": "bg",
"type": "color_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": ""
},
{
"key": "field_553b8ce8c8c3c",
"label": "Content",
"name": "content",
"type": "wysiwyg",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"tabs": "all",
"toolbar": "full",
"media_upload": 1
}
],
"min": "",
"max": ""
}
]
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "post"
}
],
[
{
"param": "page_template",
"operator": "==",
"value": "page-templates\/full-width.php"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": [
"the_content"
],
"active": 1,
"description": ""
}
]
PHP:
<?php
Class ACF_Page_Builder {
/**
* Check if Advanced Custom Fields is Active
* @var (Boolean)
*/
private $acf_active;
/**
* Check if Simple Contact Forms is Active
* @var (Boolean)
*/
private $scf_active;
/**
* The final HTML to return with the section data inluded
* @var String
*/
private $html;
/**
* Formats that can be used in the acfs_add_support and acfs_remove_support functions
* @var Array
*/
public $supported_formats;
/**
* Variable to declare whether we should use Bootstrap or not
* @var Boolean
*/
private $use_bs;
/**
* Constructor of the class. Sets some default values
*/
function __construct() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$this->acf_active = is_plugin_active( 'advanced-custom-fields/acf.php' ) || is_plugin_active( 'advanced-custom-fields-pro/acf.php' );
$this->scf_active = is_plugin_active( 'simple-contact-forms/simple-contact-forms.php' );
$this->supported_formats = array('post_type', 'page_template');
$this->use_bs = function_exists('get_field') ? get_field('acfpb_use_bootstrap') : false;
}
/**
* Enqueue the styles and scripts for the public
*/
public function enqueuePublic() {
wp_enqueue_style( 'acfpb-public', plugin_dir_url( __FILE__ ) . '../public/css/acfpb_styles.css', false, NULL, 'all' );
}
/**
* Enqueue the styles and scripts for the admin
*/
public function enqueueAdmin() {
}
/**
* Retrieves all the section HTML
* @param String $name The slug used for the sections. Is 'sections' by default
* @return String The final HTML
*/
public function getSectionsHTML( $name, $post_id ) {
if( !$this->acf_active ) return '';
if( have_rows( $name, $post_id ) ):
$s = 1;
$this->html = '<div id="acfpb_sections">';
while ( have_rows( $name, $post_id ) ) : the_row();
$layout = get_row_layout();
if( method_exists(get_class(), 'getSection_' . $layout ) ) :
$id = 'section_' . $s;
$class = 'acfpb_section section-' . $layout;
$style = get_sub_field('bg') ? 'background-color:' . get_sub_field('bg') : '';
$contained = (boolean) get_sub_field('contained', false);
if( !$this->use_bs && $contained ) $contained = false;
$wrapper = get_sub_field('wrapper_class');
$this->html .= '<div id="' . $id . '" class="' . $class . '" style="' . $style . '"><div class="sectionwrap">';
if( $contained ) $this->html .= '<div class="container">';
if( $contained ) $this->html .= '<div class="row">';
if( $wrapper !== '' ) $this->html .= '<div class="' . $wrapper . '">';
$this->html .= $this->{'getSection_' . $layout}();
if( $wrapper !== '' ) $this->html .= '</div>'; // Wrapper finish
if( $this->use_bs ) $this->html .= '<div class="clearfix"></div>';
if( $contained ) $this->html .= '</div>'; // Row finish
if( $contained ) $this->html .= '</div>'; // Container finish
$this->html .= '</div></div>'; // Section finish
$s++;
endif;
endwhile;
$this->html .= '</div>'; // Main Wrapper finish
return $this->html;
else :
return '';
endif;
}
/**
* Admin function to add the fields to wordpress. Also figures out where to show them based on the acfs_add_support and acfs_remove_support functions
*/
public function addFieldsToWP() {
if( !$this->acf_active ) return false;
if( function_exists('acf_add_local_field_group') ) {
// Get the exported field data
$json = file_get_contents( plugin_dir_path(__FILE__) . '../admin/acf-fields.json' );
$json_to_php = json_decode( $json, true );
$acf_fields_array = $json_to_php[0]['fields'];
// Check if SCF is included or leave it out of the list of fields if not
if( !$this->scf_active ) {
foreach ($acf_fields_array[1]['layouts'] as $key => $data) {
if( $data['name'] === 'simple_contact_forms' ) {
unset( $acf_fields_array[1]['layouts'][$key] );
break;
}
}
}
// Create the rest of the field group
$meta = array(
'key' => 'group_553b8b2752aba_pb10192283',
'title' => 'Page Builder',
'fields' => $acf_fields_array,
'menu_order' => 10,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => array (),
'location' => array(),
'active' => 1,
'description' => '',
);
// Filter to get the locations
$location = apply_filters( 'acfpb_set_locations', array() );
$l = 0;
foreach ($this->supported_formats as $format) {
if( !isset($location[$format]) || empty($location[$format]) ) continue;
$meta['location'][$l] = array();
foreach ($location[$format] as $place) {
$meta['location'][$l][] = array(
'param' => $format,
'operator' => '==',
'value' => $place,
);
$l++;
}
}
acf_add_local_field_group($meta);
}
}
/**
* Get the Banner section.
* @return String Final string of this section
*/
private function getSection_banner() {
$class = $this->use_bs ? 'img-responsive' : '';
$html = '<div class="banner-holder">';
$html .= '<img src="' . get_sub_field('image') . '" class="' . $class . '" />';
if( get_sub_field('use_text') ) $html .= '<div class="acfpb-hover-text">' . get_sub_field('text_on_image') . '</div>';
$html .= '</div>';
return $html;
}
/**
* Get the button section.
* @return String Final string of this section
*/
private function getSection_button() {
$class = get_sub_field('button_class');
$text = get_sub_field('button_text');
switch ( get_sub_field('link_to_page') ) {
case 'anchor':
$href = '#' . get_sub_field('button_anchor');
break;
case 'external':
$href = get_sub_field('external_link');
break;
case 'internal':
$href = get_sub_field('internal_link');
break;
default:
$href = '#';
break;
}
$html = '<a href="' . $href . '" class="' . $class . '">' . $text . '</a>';
return $html;
}
/**
* Get the Content Grid section.
* @return String Final string of this section
*/
private function getSection_content_grid() {
$blocks = get_sub_field('content_columns');
$html = '';
if( count($blocks) > 0 ) :
foreach($blocks as $block) {
$html .= '<div class="col-sm-' . $block['width'] . ' col-sm-offset-' . $block['offset'] . '">';
$html .= $block['content'];
$html .= '</div>';
};
endif;
return $html;
}
/**
* Get the Gallery section.
* @return String Final string of this section
*/
private function getSection_gallery() {
$images = get_sub_field('images');
$html = '';
switch ( get_sub_field('images_per_row') ) {
case '2':
$first_class = 'col-sm-offset-2';
$class = 'col-sm-4';
break;
case '3':
$first_class = '';
$class = 'col-sm-4';
break;
case '5':
$first_class = 'col-sm-offset-1';
$class = 'col-sm-2';
break;
case '6':
$first_class = '';
$class = 'col-sm-2';
break;
default:
$first_class = '';
$class = 'col-sm-3';
break;
}
if( count($images) > 0 ) :
$i = 1;
foreach($images as $item) {
if( $i === 1 ) $class .= ' ' . $first_class;
$html .= '<div class="' . $class . '">';
$html .= '<img src="' . $item['image'] . '" class="' . ($this->use_bs ? 'img-responsive' : '') . '" />';
if( $item['title'] !== '' ) $html .= '<h4>' . $item['title'] . '</h4>';
if( $item['caption'] !== '' ) $html .= '<p>' . $item['caption'] . '</p>';
$html .= '</div>';
$i++;
};
endif;
return $html;
}
/**
* Get the Raw HTML section.
* @return String Final string of this section
*/
private function getSection_raw_html() {
$html = get_sub_field('html');
return $html;
}
/**
* Get the Simple Contact Forms section.
* @return String Final string of this section
*/
private function getSection_simple_contact_forms() {
if( !function_exists('simple_contact_form') ) return '';
$options = array();
if( get_sub_field('form_title') !== '' ) $options['form_title'] = get_sub_field('form_title');
if( get_sub_field('button') == true ) {
$options['button'] = true;
$options['form_collapsed'] = true;
if( get_sub_field('btn_text') !== '' ) $options['btn_text'] = get_sub_field('btn_text');
}
if( get_sub_field('email_subject') !== '' ) $options['email_subject'] = get_sub_field('email_subject');
$options['return'] = true;
$html = simple_contact_form( $options );
return $html;
}
/**
* Get the WYSIWYG section.
* @return String Final string of this section
*/
private function getSection_wysiwyg() {
$html = get_sub_field('content');
return $html;
}
/**
* Get the Accordion section.
* @return String Final string of this section
*/
private function getSection_accordion_row() {
$blocks = get_sub_field('accordion_row');
$html = '';
if( count($blocks) > 0 ) :
foreach($blocks as $block) {
$html .= '<div class"accordion-title">';
$html .= $block['accordion-title'];
$html .= '</div>';
$html .= '<div class"accordion-content">';
$html .= $block['content'];
$html .= '</div>';
};
endif;
return $html;
}
}
In Portuguese-br
Olá. Estou desenvolvendo uma página que contém os campos do ACF, e estou usando o Plugin ACF Frontend do “Shabti Kaplan”, para melhorar o design do formulário.
Porém, me deparei com um Problema.
Quando eu Crio um tipo de campo”Seleção” dentro do Plugin ACF, eu consigo usar normalmente no formulário. Mas se eu ativo “Interface do campo aprimorada” nessa mesma caixa de seleção dentro do ACF, Acontece um BUG. Esse Bug é notável quando o usuário clica na caixa de seleção para escolher um valor, daí quando ele clica, a página vai para o topo… mas quando eu desativo “Interface do campo aprimorada” nao acontece esse Bug não!
Isso não é no Painel da administração… isso acontece no formulario do Usuario ou visitante na página.
AHHH , e os campos personalizados Avançados “taxonomia” e depois dentro de Taxonomia temos que selecionar a aparência deste campo. entao eu escolho “Seleção” e acontece o mesmo Bug Acima..
Creio eu que, não tem nada a ver com o plugin do Shabti Kaplan, mas sim algum bug do ACF.
In English
Hello. I am developing a page that contains the ACF fields, and I am using the ACF Frontend Plugin from “Shabti Kaplan”, to improve the design of the form.
However, I came across a Problem.
When I create a “Checkbox” within the ACF Plugin, I can use it normally in the form. But if I activate “Enhanced field interface” in that same field selection within ACF, a BUG happens. This Bug is notable when the user clicks the field selection to choose a value, then when he clicks, the page goes to the top … but when I disable “Enhanced field interface” this Bug does not happen!
This is not in the administration panel … it happens in the form of the User or visitor on the page.
AHHH, and the Advanced custom fields “taxonomy” and then within Taxonomy we have to select the appearance of this field. so I choose field type “Selection” and the same bug happens.
I believe that, it has nothing to do with the Shabti Kaplan plugin, but rather an ACF bug.
I created an image field and attached it to my CPT custom taxonomy. This part is working fine. The image field shows up in the backend dashboard.
I’m trying to query the custom taxonomy to show the top level categories with images.
Here is my function:
function rt_product_categories() {
$productcategories = get_terms(
array(
'taxonomy' => 'product_category',
'parent' => 0,
)
);
if ( !empty( $productcategories ) && ! is_wp_error( $productcategories )) {
$productcats = '<div class="aeroProducts">';
foreach ($productcategories as $category) :
$productcats .= '<div class="productEntry"><a href="'.esc_url( get_term_link( $category ) ).'">';
$productcats .= '<h3>'.$category->name.'</h3>';
if ( get_field('product_category_img', $category->term_id ) ) $productcats .= "there is a photo";
$productcats .= '</a></div>';
endforeach;
$productcats .= '</div>';
// Code
return $productcats;
} else { //end if posts
return 'no categories available';
}
}
I can’t seem to figure out how to check (and then display) the image. I’m sure I’m missing something. Any ideas what it is?
Hello,
I’ve created a custom Post Type called Events and a custom taxonomy called Speaker Names. Each time I add a new event I will assign a speaker name to the event. I’m using ACF for event details and to assign additional info (Speaker Title, Headshot, Bio, etc.) to each speaker.
The idea is to create an event and use ACF to select a Speaker (taxonomy) and it will show the custom fields (title, bio, headshot) based on that selection.
Everything displays properly on the taxonomy archive pages (example.com/speakers/jon-doe) but I can’t get it to show on any other pages (example.com/category/events). Both pages are pulling the same code so I’m not sure what the difference is. I’m not seeing any errors… the data just isn’t showing. Do I need to do something else to get the data to show on other pages?
I’m using the following rules for each Field Group.
(EventDetails) – Post Type is equal to Events
(SpeakerFields) – Taxonomy is equal to Speaker Name.
I’m using the following code to call the fields.
$term = get_queried_object();
$title= get_field(‘speaker_title’);
$headshot= get_field(‘speaker_headshot’, $term);
$bio= get_field(‘speaker_bio’, $term);
<div class=”title”><h3><?php echo $title; ?></h3></div>
<div class=”headshot”>“></div>
<div class=”bio”><h3><?php echo $bio; ?></h3></div>
Hi,
I try to get a acf from my custom taxonomy doing:
$term = get_queried_object();
$image = get_field('image', $term);
But $term is empty…
Thanks for help
Hi! I need some guidance on how to output the selected values from a select on front.
I have two options, on is a text field with a populated html value, and the second one is a post_object for products where I want to display the thumb and the permalink.
So either output the the hmtl value or the products thumb and link.
so something like:
<div class="select populated">
choice 1 or choice 2
</div>
This is how its setup in ACF:
Return format on select set to both (array). Display output set to Post object.
'sub_fields' => array(
array(
'key' => 'field_5f7efd35f2428',
'label' => 'Block one select type',
'name' => 'menu_item_type',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'checkbox' => 'Checkbox',
'product' => 'Product',
),
'default_value' => array(
),
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'ajax' => 0,
'return_format' => 'value',
'placeholder' => '',
),
array(
'key' => 'field_5f7efde2f2429',
'label' => 'Checkbox',
'name' => 'checkboxfield',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5f7efd35f2428',
'operator' => '==',
'value' => 'checkbox',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
'default_value' => '<i class="fas fa-check font-size-60 white width-1em"></i>',
),
array(
'key' => 'field_5f7f050f2d6e7',
'label' => 'Product',
'name' => 'pdp_product_one',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5f7efd35f2428',
'operator' => '==',
'value' => 'product',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'product',
),
'taxonomy' => array(
),
'allow_null' => 1,
'multiple' => 0,
'return_format' => 'object',
'ui' => 1,
),
Tried a bunch of different ways but no luck, so need to start over. Any help would be appreciated!
HI –
I have added a text field with a field name ‘lorem_ipsum’ to add an extra field to each category.
I have set show this field to:
Taxonomy is equal to Category.
The field shows on the category page in the editor ok.
I have added the field to the archive page but it is not outputting. Is there something else I need to do on category pages?
<?php
/**
* The template for displaying archive pages
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package cvb
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
if ( have_posts() ) :?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">this is the archive page', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
<p><?php the_field('lorem_ipsum') ?></p>
</header>
<?php
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main><
</div>
<?php
get_footer();
Hello,
I’m using ACF on a post type and one of those fields is a Select field that selects a Custom Taxonomy (Speaker Name). I’m also using Custom Fields for that Taxonomy (Speaker Title, Speaker Bio, Speaker Headshot, etc.). How can I pull the Taxonomy Custom Fields when the Taxonomy is selected in the Post Type.
For instance, if I select the Speaker Name “Jon Smith”, I would like to automatically pull all of Jon Smith’s info.
This works for pulling the Speaker Name
$speakname= get_field('speaker_name');
<p><?php echo $title; ?></p>
This doesn’t work for pulling the Speaker Bio
$bio= get_field('speaker_bio');
<p><?php echo $bio; ?></p>
Any idea how to get this to work?
Thanks in advance!
So, I want to use a relationship field in a block to allow the editor to choose some posts (from various post types).
But the admin / back-end performance is so bad that it’s basically unusable – it takes between 30 and 60 seconds before the field even becomes responsive and then more time to show the first set of posts in the left hand column.
I’ve set the number of posts returned in the AJAX query to 1, and that makes no difference. I suspect it’s taxonomy related (we have about 500 terms in the tags taxonomy), and if I disable the taxonomy filter in the relationship field, performance is fine.
So, what can be done to speed this up, or is the relationship field not usable with the taxonomy filter?
Hey, there — I’ve used the following function successfully on another website to display both the link and the name of a term. For some reason it only displays the link and not the name of the tag on the website I’m developing currently. Any thoughts? Thanks!
function bloaut() {
?>
<?php
$terms = get_field('blonam');
if( $terms ): ?>
<?php foreach( $terms as $term ): ?>
<a href="<?php echo esc_url( get_term_link( $term ) ); ?>" class="aut">Written by <?php echo esc_html( $term->name ); ?></a><br/>
<?php endforeach; ?>
<?php endif; ?>
<?php
}
add_action('hook_top_con', 'bloaut');
Hello,
I have Taxonomy field displayed as Select.
I would like to remove search dropdown in the field.
Stylized UI option is missing in settings in admin (It’s present in regular Select field though).
I believe I can do so using JavaScript API but can’t figure out how-to
acf.add_filter('select2_args', function(args, element, settings) {
//Something here
}
return args;
});
Hi,
On our website, we are wanting to loop through all the children of a specific product category and then display all the children ofsaid category.
So far we are able to display all the children fine, however, for SEO purposes we feel it would be helpful to be able to alter the names of the child categories for display.
For instance, say we have a category called ‘Large Umbrellas’, we want to be able to edit its name to ‘Umbrellas’ and then have the edited name display on the parent category. Hope this makes sense.
Here is how far we’ve got with the code so far.
$terms = get_terms([
'taxonomy' => get_queried_object()->taxonomy,
'parent' => get_queried_object_id(),
]);
$grade = get_field('custom_cat_title', 'product_cat' . '_' . $terms);
echo '<ul class="basel-product-categories">';
foreach ( $terms as $term) {
echo '<li class="cat-item"><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
echo $grade;
}
Hey all, question.
I working in a particular field group I created.
Is it possible so that, if a user answers a “yes” via a Radio Button field option, that the post be put in a particular taxonomy (tag or category)?
My intent is to put a form on the frontend of a website and if a user selects “yes” to a question, the post will be posted with a particular tag I’ve setup.
Thoughts?
When I use WP_Query in combination with a meta_query LIKE lookup I don’t get any results. Using get_posts works fine, but with that option I don’t get the pagination.
Querying the sql gave me this:
SELECT SQL_CALC_FOUND_ROWS beva_posts.ID FROM beva_posts INNER JOIN beva_postmeta ON ( beva_posts.ID = beva_postmeta.post_id ) WHERE 1=1 AND (
beva_posts.ID NOT IN (
SELECT object_id
FROM beva_term_relationships
WHERE term_taxonomy_id IN (1)
)
) AND (
( beva_postmeta.meta_key = 'details_land_koppeling' AND beva_postmeta.meta_value LIKE '{7676272a9b0cdf0e41c2415b4eb485868847825a24c6cb2b63d6e3518173cd7d}\"138936\"{7676272a9b0cdf0e41c2415b4eb485868847825a24c6cb2b63d6e3518173cd7d}' )
) AND beva_posts.post_type = 'post' AND ((beva_posts.post_status = 'publish')) GROUP BY beva_posts.ID ORDER BY beva_posts.ID DESC LIMIT 0, 24
As you can see the percent sign get hashed. With this it is obvious I don’t get any results. Is this a problem with the ACF plugin? After searching in Google I found this has something to do with: https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/
Could this be fixed or is there someone who can tell me where to change temporarily some ACF code?
Hello guys. I am really stuck here with this problem, so I was hoping you anyone could help. I do not ask anyone to write code for me, just to point me in the right direction.
So far, I have one select field and one repeater that has post object inside.
Select field is currently listing all taxonomy categories, which is good.
Post object is fetching all posts from database (acf/post_object/query/).
My goal is to select whatever taxonomy, and then, when I want to add some post, I want to be able to choose only from posts that are ‘from’ that taxonomy, not all posts, since I have too many of them.
I managed to enqueue admin script, but I can’t get the value of selected field for a first step.
I think this should be done like this :
– The moment I select some taxonomy, it triggers function in javascript, make ajax call to retrieve posts with that taxonomy, then populate posts with those posts.
Is this possible to do it this way or I need some different approach? If so, can someone give me some directions.
Best regards,
Mark.
hello everyone
i need help to display taxonomy with text from repeater?
this code working but content from custom taxonomies duplicates to frontend
im not understand this it.
<div class="s-container">
<div class="s-slider -m1.2 -d5">
<?php if(have_rows('cast')):
while(the_repeater_field('cast')):
$tax = 'celebrity_cat';
$types = get_terms( array(
'order' => 'des',
)
);
foreach($types as $type) {
$term_link = get_term_link( $type );
$image = get_field('celebrity_avatar', 'celebrity_cat_' . $type->term_id . '' );
$charecter = get_sub_field('charecter');
if ( has_term( $type->term_id, 'celebrity_cat')) {
?>
<div class="slider">
<article id="post-<?php the_ID(); ?>" <?php post_class('content-item -card'); ?>>
<?php
echo '<div class="pic">';
echo '<a href="' . esc_url( $term_link ) . '">';
echo '<img width="350" height="184" src="' . $image['url'] . '" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" ';
echo '</a>';
echo '</div>';
echo '<div class="info">';
echo '<header class="entry-header">';
echo '<h3 class="entry-title">';
echo '<a href="' . esc_url( $term_link ) . '">';
echo '<span>'. $type->name . '</span>';
echo '</a>';
echo '</h3>';
echo $charecter;
echo '</header">';
echo '</div>';
//break;
?>
</article>
</div>
<?php } } ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>