Hello! I’m building a website with custom post types thanks to ACF (💖) along with Elementor, but I have a question. I want to maintain a specific structure for the CPT I have created. I have created a post type (surgery) and a taxonomy for it (surgery-cat).
This has created the following URL for the posts:
(post type) domain.com/surgery/surgery-name-post
And for the taxonomy domain.com/surgery-cat/surgery-cat-name
What I really want is for the URL to have the category name and for the category to work on its own showing the posts (I would do this with Elementor) and remove the post/taxonomy name from both.
Post type domain.com/surgery/surgery-name-post >>>>> domain.com/surgery-cat-name/surgery-name-post
Taxonomy domain.com/surgery-cat/surgery-cat-name >>>>> domain.com/surgery-cat-name
Is it possible to do this?
Thanks!!
I have created a custom post type, let’s call that Cars.
I have also created a custom Taxonomy called Car Manufacturers.
Now, I’d like to create a custom URL for the cars so it’s domain.com/cars/car-manufacturer/{car name}
Where, cars = custom post type, car-manufacturer = custom taxonomy and car name = the specific post name.
By default it’s domain.com/cars/{car name}
What is the correct custom URL structure for this?
hello I create a taxonomy “brand” with acf plugin for woocommerce products
and now how can I show product brand in their page ?
Hi there
I’ve created a custom post type “Books” Below that I’ve added a Taxonomy “Books” as well. Now on the Add New Book page i am unable to display “Biology” that is a Child Taxonomy. I’ve already added “Biology” at taxonomy page.
How can i display this on my edit / add book page?
Regards
I created a custom post type ‘products’ using ACF.
Then, I created the taxonomy ‘product categories’.
Now, when I click ‘view’ on one of these taxonomies like ‘t-shirts’,
I end up on this URL: ‘/product-category/t-shirts/’
I would like my URL to be: ‘/products/t-shirts/’
So, I tried going to the URL section of the taxonomy select ‘permalink rewrite’ and entered ‘products/’ in the URL slug.
Now, when I click ‘view’ on ‘t-shirts’, I end up on this URL: ‘/products/t-shirts/’, which is correct, but the page is a 404.
Am I missing a step?
Hello,
I’m working on a website with a search bar based on 2 taxonomies, City and Project. From the search bar the user selects a ‘City’ first and then the ‘Project’ dropdown updates based on the companies available in the initial city selected. Once the user click ‘search’, the website redirects them to a result page where all the companies shown are based on the previous selection.
I need to show on this page a title with the taxonomy name selected for the ‘city’ on top of the page. I have created the taxonomy and gave a key name ‘city_acf’. Is there anyone kind enough to help me sort this?
Thank you so much in advance.
Matt
Hi,
I have created a custom post type “Stories” where I’ve also created a custom taxonomy named “Segment”. Connected to this custom taxonomy I’ve created a custom field “segment_image” (set to array) ruled to be shown if Taxonomy is equal to “Segment”. The idea is that each term will have an image assigned and will be displayed in the post depending on the segment chosen.
In the back-end everything seems to be connected correctly and the field is showing in the Taxonomy page to upload an image. The problem I’m having is that I can’t find the way to retrieve that image ID or URL in my template page.
Here is my code:
<?php
$args = array(
'post_type' => 'stories',
'post_status' => 'publish',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$segment = get_field('segment_story');
$segment_bg = get_field('segment_image', $segment);
echo 'bg: ' . $segment_bg['url'];
I’ve even created a Taxonomy field type in my custom post type “Stories” called “segment_story” to force getting the term array manually but still nothing.
I would appreciate any help with this! I’ve checked several ACF documentation pages and also checked some threads here but nothing worked for me so far.
Thanks in advance!
I.
Working with a front-end form, I want to programmatically set the value of a select2 taxonomy field after another field is updated.
I have tried all manner of updating the value but it either doesn’t change or gets set to null. Any ideas? I thought I had a very simple task at hand, but its eluding me.
This is what I have tried:
const selectedValue = 12; //the id of the term I want to select
$('#acf-field_5dcc4aa906709').val(selectedValue).trigger("change");
var countyfield = acf.get_field('field_5dcc4aa906709');
countyfield.val(selectedValue);
The first one should work according to the select2 documentation. This actually sets the value of the field to null.
The second one I got from the ACF documentation. This updates the field object but does not update the field in the UI.
Hi,
I am performing an import of more than 500 items with the wp-ultimate-csv-importer free version.
I managed to import all the ACF fields except for the relationship and taxonomy fields.
As I read in this post: https://support.advancedcustomfields.com/forums/topic/importing-data-2/, serialized arrays of post IDs are used for relationships, serialized arrays of term IDs are used for taxonomies.
I am trying to upload a CSV formatted like this:
Title;Relationships;Taxonomies
Test;”a:2:{i:0;i:651;i:1;i:649;}”;”a:2:{i:0;i:18;i:1;i:19;}”
It doesn’t work.
Is there a way to import these fields? How should the CSV be formatted?
Expected Behavior:
I would expect the No Meta Box selection in the Meta Box field on the settings for my taxonomy: [My Taxonomy] > Advanced Settings > Visibility would hide the Taxonomy Options from my post editor.
Actual Behavior:
The Taxonomy Meta Box still appears in the post editor. The only way to hide it is to hide it completely by toggling the Show in UI to off, but I still want to be able to see my Taxonomy and terms in the dashboard.
Hello, I am writing a cpt with acf, and one of the fields, show the exact same text for every post in the CPT (the first one). If I set it as draft it moved to the second.
The strange part is that every other field in the loop works perfectly, only this one is problematic. The field is ‘testimonial_text’;
Here is my code:
// Testimonial Slider Shortcode
function testimonial_slider_shortcode($atts) {
$atts = shortcode_atts( array(
'category' => '',
), $atts, 'testimonial-slider' );
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => $atts['category'],
'operator' => 'AND'
)
)
);
$testimonials = new WP_Query($args);
$output = '<div id="testimonial-slider" class="carousel slide full-width" data-ride="carousel">';
$output .= '
$i = 0;
while($testimonials->have_posts()) {
$testimonials->the_post();
$output .= '<li data-target="#testimonial-slider" data-slide-to="'.$i.'" class="'.($i == 0 ? 'active' : '').'">';
$i++;
}
wp_reset_postdata();
$output .= '
<div class="carousel-inner">';
$i = 0;
while($testimonials->have_posts()) {
$testimonials->the_post();
$post = get_post();
$person_name = get_field('person_name');
$testimonial_text = get_field('testimonial_text');
$company_text = get_field('person_company');
$person_photo = get_field('person_photo');
$person_photo_url = $person_photo['sizes']['large'];
$output .= '<div class="item '.($i == 0 ? 'active' : '').'">';
$output .= '<div class="inner-testimonial">';
$output .= '<div class="carousel-caption">';
$output .= '<div class="block-quote-img">';
$output .= '';
$output .= 'test';
$output .= '<span class="author-text" maxlength="2">' .$testimonial_text. '</span>';
$output .= '</div>';
$output .= '<p class="author">' .' - ' .$person_name.' , '.$company_text.'</p>';
$output .= '</div>';
$output .= '<div class="img-div">';
$output .= '';
$output .= '</div></div></div>';
$i++;
}
wp_reset_postdata();
$output .= '</div><span class="glyphicon glyphicon-chevron-left"></span><span class="glyphicon glyphicon-chevron-right"></span></div>';
return $output;
}
add_shortcode('testimonial-slider', 'testimonial_slider_shortcode');
// Enqueue styles and scripts
// Global plugin styles should be added to testimonails slider.css
// Per project styles should be added to testimonial-project.css
function testimonial_slider_scripts() {
wp_enqueue_style( 'testimonial-slider-style', plugins_url( '/testimonial-slider.css', __FILE__ ) );
wp_enqueue_style( 'testimonial-project-style', plugins_url( '/testimonial-project.css', __FILE__ ) );
// wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css');
// wp_enqueue_script(
// 'testimonial-block-script',
// plugins_url( 'blocks/testimonial-block.js', __FILE__ ),
// array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components' )
// );
}
add_action( 'wp_enqueue_scripts', 'testimonial_slider_scripts' );
// Register Gutenberg Block
add_action('init', 'wp_testimonial_block_init');
function wp_testimonial_block_init() {
register_block_type(__DIR__ . '/build', array(
'render_callback' => 'theHTML'
));
}
function theHTML($atts) {
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => $atts,
'operator' => 'IN'
)
)
);
$testimonials = new WP_Query($args);
$output = '<div id="testimonial-slider" class="carousel slide full-width" data-ride="carousel">';
$output .= '
$i = 0;
while($testimonials->have_posts()) {
$testimonials->the_post();
$output .= '<li data-target="#testimonial-slider" data-slide-to="'.$i.'" class="'.($i == 0 ? 'active' : '').'">';
$i++;
}
wp_reset_postdata();
$output .= '
<div class="carousel-inner">';
$i = 0;
while($testimonials->have_posts()) {
$testimonials->the_post();
$post = get_post();
$person_name = get_field('person_name');
$testimonial_text = get_field('testimonial_text');
$company_text = get_field('person_company');
$person_photo = get_field('person_photo');
$person_photo_url = $person_photo['sizes']['large'];
$output .= '<div class="item '.($i == 0 ? 'active' : '').'">';
$output .= '<div class="inner-testimonial">';
$output .= '<div class="carousel-caption">';
$output .= '<div class="block-quote-img">';
$output .= '';
$output .= '<span class="author-text" maxlength="20">' .$testimonial_text. '</span>';
$output .= '</div>';
$output .= '<p class="author">' .' - ' .$person_name.' , '.$company_text.'</p>';
$output .= '</div>';
$output .= '<div class="img-div">';
$output .= '';
$output .= '</div></div></div>';
$i++;
}
wp_reset_postdata();
$output .= '</div><span class="glyphicon glyphicon-chevron-left"></span><span class="glyphicon glyphicon-chevron-right"></span></div>';
return $output;
}
This is the code for the acf register
// Add Custom Fields
function add_testimonial_custom_fields() {
if(function_exists('acf_add_local_field_group')):
acf_add_local_field_group(array(
'key' => 'group_testimonial',
'title' => 'Testimonial Fields',
'fields' => array(
array(
'key' => 'field_person_name',
'label' => 'Person Name',
'name' => 'person_name',
'type' => 'text',
'required' => true,
'show_in_rest' => true,
'wrapper' => array(
'width' => '50',
),
),
array(
'key' => 'field_testimonial_text',
'label' => 'Testimonial Text',
'name' => 'testimonial_text',
'type' => 'wysiwyg',
'required' => true,
'show_in_rest' => true,
'wrapper' => array(
'width' => '50',
),
),
array(
'key' => 'field_person_photo',
'label' => 'Person Photo',
'name' => 'person_photo',
'type' => 'image',
'preview_size' => 'full',
'required' => false,
'show_in_rest' => true,
),
array(
'key' => 'field_person_company',
'label' => 'Company',
'name' => 'person_company',
'type' => 'text',
'required' => false,
'show_in_rest' => true,
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'testimonials',
),
),
),
));
endif;
}
add_action('acf/init', 'add_testimonial_custom_fields');
Dear ACF Community.
I’m struggeling with something that is in fact very simple, and i suppose it’s an easy thing for some of you to solve.
I have several blog posts for bicycle tours attached to a custom taxonomy for countries.
I also have set up a custom post type for countries, to write a bit about the country and show only blog posts for this country, according to the category.
But i don’t get it run, that only blog posts for this country are shown on the country page.
The URL for the country page would be e.g. https://www.rogonneur.com/country/germany/
And the Post to appear in the blog teaser section there would be e.g. https://www.rogonneur.com/cycling-to-watch-the-first-freiburg-international-match-in-years/ as it’s only connected to the category “germany”.
Is this somehow too advanced? I’d appreciate any help!
Kind regards,
Dominic
Hello, I have made a field to add to the Woocommerce attributes. I have added a picture below for more clearancy.
I am trying to display the field on the single product page. I have added the following code to the content-single-product.php template file.
$terms = get_the_terms( $product->id, 'pa_merk');
var_dump($terms);
$image = get_field('afbeelding_merk', $terms->taxonomy . '_' . $terms->slug);
// Display the image if it exists
if ($image) {
echo '<img src="' . $image . '" />';
} else {
echo "<p>Foto niet gevonden.</p>";
}
What am I doing wrong?
Hi,
I found a bug in the relationship between a custom taxonomy and the users.
I have a custom taxonomy ‘genres’ with an assigned field group with a field for assigned users.
Name: ‘rel_users’
Field Type: User
Select Multiple: True
Bidirectional Target Field: rel_genres
A second field group is assigned to ‘users’ and has a field for assigned taxonomy.
Name: ‘rel_genres’
Field Type: Taxonomy
Appearance: Multi Select
Bidirectional Target Field: rel_users
If I assign a user to a genre term, everything is ok.
term_id: 15
user_id: 5
wp_usermeta
meta_key: rel_genres
meta_value: a:1:{i:0;s:2:”15″;}
wp_termmeta
meta_key: rel_users
meta_value: a:1:{i:0;s:1: “5”;}
In the backend the relations are displayed correctly in the user profile and on the taxonomy edit page.
However, when I make changes on the taxonomy edit page, the target value is changed incorrectly (when I delete, save and reassign the user) so that the assignment in the user profile disappears. When saving the taxonomy term, the bidirectional target field is now saved as an interger array instead of string array.
wp_usermeta
meta_key: rel_genres
meta_value: a:1:{i:0;i:15;} <- integer array!
wp_termmeta (unchanged)
meta_key: rel_users
meta_value: a:1:{i:0;s:1: “5”;}
It seems that the array with integer values destroys the relationship on the side of the user.
best regards
steffen
I have created a custom taxonomy (book authors). Now I want to show all book authors and their respective custom fields on a page, how do I do that?
Hello, everyone,
I need help in realizing client requirements.
Within the ACF group, I’ve created three fields (primary_tags, secondary_tags, and other_tags), all of which are of type taxonomy (tag). “Create terms” is set to “switch on,” return value is “term object,” and appearance is set to “multi-select.” These fields are displayed on the posts.
My client requests that only administrators can add new primary and secondary tags to the list, while other users can only add tags that already exist in the list. As for the “other_tags” field, it is open to all users.
If you have any ideas on how this could be achieved, please send me your suggestions. Thank you in advance!
I’m using ACF to make taxonomies in a field group together with Woo, adding the fields to my products.
However, I want the object of the taxonomy and not the ID but when I set it to “Term object” the entire page where this is referenced crashes, no matter if I’m doing it through WP Bakery or shortcodes.
Is there a clash somewhere? I’ve tried to use really unique names. It only crashes the site if it’s on “Term object”, not “Term ID” and it only crashes if the field has a value associated with it.
Hello,
I was able to set a default post taxonomy but it does not show the ACF Field group until I manually click on it to change it. Can you provide any insight? I think I would need to trigger an event by javascript to show but I am not sure how to do that.
To clarify, I have three post taxonomies: TBL, FBL and College. The location rules in ACF are to show depending on which taxonomy is selected. I have set a default to TBL but even though it is selected as default and checked the ACF Field Group Box for TBL does not show until I click on another option and back on TBL. I would like the TBL field box to show on page load.
Eventually, I would like it to show the ACF field box for the last selected option be it TBL, FBL or College on page load.
Thank you for your help in advance and great plugin by the way!
David
I need a solution to provide a single True/False field with the ability to activate a special taxomy term in the backend of a custom post type entry.
Thanks in advance for any help!
I successfully used ACF custom taxonomies to add Media categories. I added the dropdown filter via functions.php to the Media Library and can sort items while I’m in the Media Library. But I don’t know how to add this dropdown to the Select or Upload Media modal so I can filter images by category when adding images in a post or page. Is this even possible to do? If it is, can someone point me in the right direction or documentation for this?
Hello, I’ve got a teaser snippet that pulls the taxonomy info for a custom post type and works fine when using a wpquery:
setup_postdata($post);
$postid = $post->ID;
$item_image = get_field("listing_image", $post->ID);
// TAXONOMY //
$taxonomy = 'types';
$terms = get_object_term_cache( $postid, $taxonomy );
$outputpill = '';
$i = 1;
$teasertype = '';
foreach($terms as $term) {
if ($i == 2) { break; }
if(!empty($outputpill))
$outputpill .= '';
$outputpill .= '<div class="cat cat-pill pill-'. $term->slug . '">'.$term->name.'</div>';
$teasertype = $term->slug;{}
$i++;
}
// BUTTON SWITCH //
if($teasertype){
switch($teasertype){
case 'article':
$ctaclass= "article";
$ctatext= "Read Now";
etc etc etc
When I use this snippet on another page that references these custom post types using a Post Object field, it throws an error when looking up the taxonomy:
Warning
: foreach() argument must be of type array|object, bool given in
/Users/louis.plante/Local Sites/smartvaultcom/app/public/wp-content/themes/smartvault-wordpress-website/inc/snippets/_incl_resources–teaser.php
on line
17
Code used:
<?php $post_objects = get_field('campaign_group1_item_resource'); ?>
<?php
if( $post_objects ):
foreach( $post_objects as $post):
setup_postdata($post); //set new $post_object
get_template_part( 'inc/snippets/_incl_resources--teaser' );
endforeach;
wp_reset_postdata(); //reset global $post
endif;
?>
Hi there! I’m not a developer, just a Dad that is trying to create a cool website for his Jazz Musician son. While I’m using Elementor, I’m also trying to minimize plugins. That said, I’ve created a Custom Post Type called “Gigs” to dynamically highlight upcoming shows that my son will be playing. I’ve also created a Custom Taxonomy called “Locations” to dynamically bring in Map, Location URL, and Image for instance. I cannot get any of these custom fields associated with the Locations Taxonomy to display. I’ve also created a second CPT called “Gig Locations” and tried to relate them to the Gigs CPT so that I could display its respective custom fields.
I can place an ACF Google Maps field directly in the Gigs CPT and it will display through the Elementor Google Maps widget. But the ACF Google Maps fields in either the Taxonomy or 2nd CPT will not display. When attempting to put custom PHP code snippets to “get_meta_terms” etc., nothing happens or the site crashes entirely.
Thanks in advance for your help!
qthornton.com
Just migrated from CPTUI. Tried to create a new taxonomy for a CPT. The response said it was created, but the only data that gets saved is the name of the taxonomy. Nothing else. Has anybody experienced this and found a solution? Thanks.
Hi,
I created a portfolio taxonomy with ACF and I’m trying to pass trough a tag field from Gravity Forms to this taxonomy. But isn’t works.
This is the code:
add_filter(“gform_post_data”, “custom_taxonomy”, 10, 2);
function custom_taxonomy($post_data, $form){
//—————————————–
//Replace “post_tag” with your taxonomy name
$custom_taxonomy = “obituarios_localidades”;
//—————————————-
$tags = implode(“,”, $post_data[“tags_input”]);
$post_data[“tax_input”] = array($custom_taxonomy => $tags);
$post_data[“tags_input”] = null;
return $post_data;
And the portfolio categories are: Obituarios
Localidades
Can anyone help me please?
Thanks.
1- My issues is: the new articles, moved from “wordpress > articles” to a new post type made by ACF, cannot read the new category (taxonomy with hierarchy) and tag (taxonomy without hierarchy) that I created on ACF.
For example, based on my theme, the category of an article shows above the article’s title. Now, the articles under a new post type shows the old category, but not the the new category (taxonomy with hierarchy).
based on my theme, the tag of an article shows at the end of the article. Now, the articles under a new post type shows the old tags, but no the new tag (taxonomy without hierarchy).
A friend of mine recommended me to build a new template for single post for the new post type, but I’m wondering if there is any other ways to do it. Thank you.
And my next question would be…if this works, how I can make the “apprearance > widgets > mian sidebar” to read all category or tag from different post types…
Thanks for your answers.