Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

topic

  • Helping

    How to query event post type after current date with multiple taxonomies

    I’ve created an Events post type that is categorized using two taxonomies: Event Type and Academic Program

    I’m able to create list of Event posts and include a filter form to pull up specific events categories based on what’s selected in two drop down selections.

    I want to filter the page by checking the current date and only posting events greater than the event_starting_date which is a datepicker field.

    The first section is working code that allows the filtering dropdown:

    <?php
    $args = array(
    'taxonomy' => 'academic_programs',
    'show_option_all' => '- Any -',
    'show_count' => 0,
    'name'  => 'academic_programs',
    'orderby' => 'name',
    'value_field' => 'slug',
    'echo' => 0
    );
    $select = wp_dropdown_categories( $args );
    $select = preg_replace("#<select([^>]*)>#", "<select$1> ", $select);
    echo $select;
    ?>
    
    <?php
    $args = array(
    'taxonomy' => 'event_type',
    'show_option_all' => '- Any -',
    'show_count' => 0,
    'name'  => 'event_type',
    'orderby' => 'name',
    'value_field' => 'slug',
    'echo' => 0
    );
    $select = wp_dropdown_categories( $args );
    $select = preg_replace("#<select([^>]*)>#", "<select$1> ", $select);
    echo $select;
    ?>

    This is where I believe I have an issue:

    <?php
        $queried_object = get_queried_object () ;
        $today = date('Ymd');
        $args = array (
            'category_name'  => 'events',
             'posts_per_page' => 6,
             'orderby'   => 'meta_value',
             'meta_key' => 'event_start_date',
             'order' => 'ASC',
             'meta_query' => array(
                array(
                    'key' => 'event_start_date',
                    'meta-value' => $value,
                    'value' => $today,
                    'type' => 'DATE',
                    'compare' => '>=')),
        ) ;
        $query = new WP_Query ($args) ;
        ?>

    Everything past the orderby argument down to the meta query array is where things seem to break.

    This is how I get the query to post. If I leave out the above code block and remove the $query variable, I do get the filter to work, albeit without the necessary sort.

    <?php if ( $query->have_posts() ) {  while ( $query->have_posts() ) : $query->the_post(); ?>
                            <span><?php $date = get_field('event_start_date');
                            $starttime = get_field('event_start_time');
                            echo $date . " - " . $starttime; ?></span></br> 
                         <?php endwhile; } ?>

    Any help would be appreciated.

  • Helping

    Copy taxonomy values to a custom fields

    Hi,
    I’m trying to copy the value of a taxonomy named item_year to the newly created custom field named year for each of my posts. Notice that year doesn’t have anything to do with the “real” year of the post creation, it’s just a meta description.
    Do you think that there’s an automatic way to do that without going over all my posts and manually copying the value of each item_year for the custom field?

    I found a script that does similar thing with other plugin, do you think it can be modified to work with ACF as well?
    https://wp-filter.com/howto/convert-taxonomies-terms-values-meta-values/

    Thanks a lot!

  • Solved

    ACF Front End Form taxonomy field "Loading Failed" in production only

    Hello there,

    First, I use ACF PRO 5.11.4 and the latest WordPress 5.8.3

    I’m wondering why the taxonomy fields doesn’t work in my ACF front end form.
    Everything runs fine in localhost (Wamp).
    Then I tried in production environment with 2 different webhosts and I get the same error message “Loading failed“.

    It’s the exact same site in localhost and production.
    No error in DEBUG mode (WP_DEBUG, WP_DEBUG_LOG and SCRIPT_DEBUG).
    I tried with all plugins disabled except ACF PRO.
    The same scripts are well loading in the same order in local and prod when I look at in in the console.

    Seriously I think there is a parameter to change at my webhost but I don’t know what.
    ANd it seems to be a general problem with most of webhost.

    Do you have an idea ?

  • Solved

    Custom taxonomy acf value in loop on other pages

    Hi. Viewed lots of topics, but still didn’t found an answer.

    So, I have custom post type “flat4” and taxonomy “floor4”. On Front page I’m calling get_categories() and looping through taxonomy to get link and other stuff. I have acf to this taxonomy, and I need to output it in loop. Found this code: <?php the_field(‘hover’,’floor4_’ . $cat->term_id); ?>, but it’s not working.

    Can you please help me with it?

  • Solved

    Is there a way to update a custom taxonomy using front end form?

    I have a custom taxonomy and would like the core WordPress custom taxonomy of the post to update using the ACF taxonomy field on my front end form on creation and update from the front end. Does anybody know how to achieve this?

  • Helping

    Retrieve Field Value from Custom Taxonomy and display it on Custom Post Type

    I’ve created a custom post type ‘movies’ and custom taxonomy ‘scategory’ for posts. Now in template, when i trying to get selected trems by get_field() it’s not retrieving field values.

  • Solved

    Filter products/categories/ by ACF field

    Hello,
    I try to filter the list of categories of the products received bu the rest api.
    I add ‘myfield’ as ACF field.
    With the plugin ACF-to-rest-api I can see the field in the rest api result under acf : {}

    This url returns all the categories.
    https://mywebsite/wp-json/wc/v3/products/categories/

    I want to be able to filter a custom field added by ACF
    https://mywebsite/wp-json/wc/v3/products/categories/?myfield=testvalue

    Could someone help me ?

    I suppose there is a filter or an action to add in the functions.php file but everything I tried returned all the categories without any filter.

    What’s also strange, for the products, I can see in the rest api result the metadata with the values added by ACF
    For the category, the metadata aren’t visible.
    In the database the values are stored in termmeta for the categories and in postmeta for the products.
    If I’m right, the product is a post and the category is a taxonomy.

    Thanks in advance,

  • Solved

    When to use ACF select field over taxonomy?

    I just started out with ACF Pro a couple of weeks ago, not learning yet to custom code it but work with some ACF plugins.

    I am building a WooCommerce store (think books & authors) and want to add the country to the author.

    As far as I see it, I have several options
    1. Add country as a custom field / select and just list each country per line in ACF backend

    2. Add a custom taxonomy and connect it to the author. Next, add the taxonomy as an ACF field

    For my use case, the 1st attempt would probably be sufficient.

    However, when would it be better to create a custom taxonomy instead?

  • Helping

    Using Category Color Picker Value In Home Loop

    How to get the value from category color picker field for single post excerpts displayed on home page.

    Something like this but in the home.php loop to style post excerpts based on the value added via the Edit Category field using color picker. https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

  • Solved

    Filter post object based on selected taxonomy

    Hello,
    I have a pretty simple app. there are two selects on an options page. the first select is for an admin to select a taxonomy (some category). then I need the next select to be able to populate with posts that have that category.

    I was thinking this would be somewhat easy but I’m having a hard time since I can’t use acf/fields/post_object/query (docs) because I need the value of the category field which I don’t think I can get with PHP.

    I’ve been messing around with the ajax filters and found select2_ajax_data (docs) but I’m unsure how to change the query.

    Appreciate any help, Thanks!

  • Solved

    update_field after create post by code

    Hi

    i have question about update_field after creating a post by code (importing from xlsx)

    I have some acf fields (users and taxonomies) in a custom post type “match”, so i have winners, loosers, and a multiple taxonomy select

    i create post like this

    $postarr = array(
    'post_title' => sanitize_text_field( wp_unslash( $titolo_post ) ),
    'post_status' => "publish",
    'post_type' => "fight",
    );
    $post_id = wp_insert_post( $postarr);	

    and then i try to update fields

    update_field("match_valevole_per_titolo",$id_titoli,$post_id);
    update_field("vincitore",$lista_vincitori,$post_id);

    where $id_titoli is an array with taxonomy ids, and $lista_vincitori is array with users ids

    In the backend, if i enter in the post, i see all fields correctly, but quering posts there is something that is wrong BUT it is fixed if i save post (witout modify any field) from backend….just like saving updates something…. what i’m doing wrong?

  • Unread

    Taxonomy term name(value) > to post meta field

    Good day friends, I am coming back to ACF and need your help with one thing because I don’t know how to achieve this.. There is many information about it but any doesn’t fit my needs and custom functions just doesn’t work.

    What I am trying to do is: GET taxonomy ‘car_model’ term name(value) ‘bmw’ and paste it (parse) inside custom post type ‘cars’ meta field ‘car_model’.

    Maybe someone can help me with this? I am not strong in coding, but would be really appreciated for help.

    I am trying to use this code:

    `function my_acf_save_post( $post_id ) {
    $field = get_field_object( ‘car_model’ );
    $value = $field[‘value’];
    $label = $field[‘choices’][ $value ];
    $value1 = get_field( ‘car_model’, $post_id );

    update_field( ‘car_model’, $value1, $post_id );
    }
    add_action(‘acf/save_post’, ‘my_acf_save_post’, 20);

    Anyone can help me with this?

    F.A.Q:
    1) There is a lot of terms, but only 1 will be available to choose from all and display.
    2) I need this function to parse term name(value) to custom post meta field.
    3) No really I am just beginner who is trying to study hard to work with PHP, WP, ACF once again without stopping.

  • Helping

    ACF Fields now showing in "rest_do_request" result

    Hi. I have some ACF fields defined on both a custom post type and custom taxonomy. All works well (GET and POST) when accessing the REST API “traditionally”, but when we use the internal REST functionality using the “rest_do_request()” function in our template, the result does not include the ACF fields. (Switching the “ACF to REST API” plugin does work, but causes other issues.) Any help would be greatly appreciated…

  • Helping

    get_the_terms() don't retrieve custom fields

    Hi,

    i have a custom taxonomy named “Contact”
    For this taxonomy, i have 2 custom fields named “Email du contact” and “Télephone du contact”

    I can’t retrieve those 2 custom fields

    I try to do this :

    $terms = get_the_terms( get_the_ID(), 'contact' );

    But when i do a print_r, i have my taxonomies without those 2 custom fields :

    Array
    (
        [0] => WP_Term Object
            (
                [term_id] => 127
                [name] => Contact 1
                [slug] => contact-1
                [term_group] => 0
                [term_taxonomy_id] => 48
                [taxonomy] => contact
                [description] => 
                [parent] => 0
                [count] => 5
                [filter] => raw
            )
    
        [1] => WP_Term Object
            (
                [term_id] => 130
                [name] => Contact 2
                [slug] => contact-2
                [term_group] => 0
                [term_taxonomy_id] => 51
                [taxonomy] => contact
                [description] => 
                [parent] => 0
                [count] => 1
                [filter] => raw
            )
    
    )

    Contact taxonomy

    Thanks for your help

  • Unread

    Add Fields to Woocommerce Reviews Form

    Hi,

    so far I have done only very simple things with ACF, and wonder if following is even possible. I know it is a more difficult and extensive questions with multiple steps. I really appreciate any input on one of them.

    I want to add some fields to the Woocommerce Reviews Form. Out of the Box it is just 5 Stars and a comment textfield.

    Example:

    The shop sells books. I created a taxonomy for the characteristics of the book with terms like “thrilling”, “spooky”, “funny”, etc. When a user writes a review, in addition to the 5 Stars and comment, I want him to pick multiple of those terms, that descripe the book best in his opinion.

    When he sumbmits his Review I want the chosen terms to be displayed in his review.

    Above the reviews a summary is displayed with the average 5 Star ratings of all reviews. I would like to display the chosen Taxonomy terms of all reviews there, too. But only the three most used ones.

    The Users are already able to filter the Woocommerce shop with certain taxonomies. I would like those products to appear when you filter for one of those top 3 Terms in the summary.

    Thanks for your support!

  • Solving

    Add taxonomy terms to custom post type from posts in relationship field

    Hello,

    I have two CPT’s – “Resource” and “Publication”. Both share similar taxonomy’s, “Type” for example. “Publications” can be linked to “Resources” via an ACF relationship field using post objects.

    Is there a way to add the taxonomy terms from the “Publications” to the “Resource” when the pubs posts are added via the relationship field? So the “Resource” would inherit all the “Types” from the pubs contained within, as it were?

    Thanks!

  • Helping

    Showing ACF taxonomies as classes

    Hello,
    I’m using a taxonomy field and I’m trying to show the terms used as a class name in a div.

    Something like:
    <div class="term1 term2 term3">Item</div>
    Where these terms are grabbed from the taxonomy field in the panel.

    Does anyone know how can I show the items without whitespace, commas, or anything? Just one next to the other with an space, like normal CSS classes.

    Thanks in advance

  • Solved

    Get term ACF Image Field

    I have code to load the last 6 terms and only use terms without children so I get the months and not the years which are both part of the same Taxonomy as terms. I can already load the titles as links, but I am trying to load the attached ACF image field which I am failing to do.

    I use $summaryimage = get_field('summary_preview_image'); inside this block.php file to then use it for wp_get_attachment_image( $summaryimage, $size ). But it seems that the variable is not loading anything and so my term image is not being loaded. Question is why this is not working inside wp-content/themes/theme/blocks/spotlight/block.php I am guessing cause I perhaps need to indicate more in the get_field request to grab the image from the specific group which is used to attach a custom filed to the term.. But how?

    $args = array( 'hide_empty=0', 
                    'childless'     => 1, 
                    'number'        => 6,
                    'orderby'       => 'ID', 
                    'order'         => 'ASC'
                    ); 
    
    $terms = get_terms( 'molecules_of_the_month', $args );
    if ( ! empty( $terms )   ) :
        $summaryimage = get_field('summary_preview_image');
        print_r($summaryimage);
        $size = 'full'; // (thumbnail, medium, large, full or custom size)
        $count = count( $terms );
        $i = 0;
        $term_list = '<p class="molecule-of-the-month">';
        ?>
        <div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
            <div class="slider mobile-slider splide" data-splide='{ "type" : "loop", "perPage": "3", "arrows": 0, "breakpoints": { "99999": { "destroy": 1 }, "767": { "perPage": "1" } } }'>
                <div class="splide__track">
                    <ul class="post-grid splide__list">
                        <?php 
                        if($term_list):
                            foreach ( $terms as $term ) {
                                $i++;
                                $term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under %s', 'drughunter' ), 
                                $term->name ) ) . '">' . $term->name . '</a><figure class="post-featured-image">' . 
                                wp_get_attachment_image( $summaryimage, $size )
                                . '</figure>';
                                
                                if ( $count != $i ) {
                                    $term_list .= ' &middot; ';
                                }
                                else {
                                    $term_list .= '
    ';
                                }
                            }
                            echo $term_list;
    
                        endif; ?>
                    </ul>
                </div>
            </div>
        </div>
    <?php endif;?>
  • Solving

    Get taxonomy values

    Hi,

    I try to get taxonomy values of my ACF color picker but my fucntion returns empty.
    Do yo know where i am wfong please ?
    Taxonomy slug = portfoliocategories
    Terms slug = sport, culture, others
    Acf slug = couleur

    add_shortcode(  'acf_colour' , 'get_colour');
    
    function get_colour( $atts ) {
    
    $queried_object = get_queried_object(); 
    $term_id = $queried_object->ID; 
    $terms = wp_get_post_terms($term_id ,'portfoliocategories');
     
          foreach ( $terms as $term ) {
            
           $colour= get_field('couleur', $term->taxonomy . '_' .$term->term_id  );
    
           print_r ($colour);
       }
    
     return  $colour  ;
    }
  • Solving

    Post Object at random

    We have added an advanced custom fields block to load a post object on the home page with the latest custom post type post. This setup allows us to choose a post to display.

    "fields": [
      {
          "key": "field_xxxxxx",
          "label": "Label",
          "name": "motd",
          "type": "post_object",
          "instructions": "",
          "required": 0,
          "conditional_logic": 0,
          "wrapper": {
              "width": "",
              "class": "",
              "id": ""
          },
          "post_type": [
              "label"
          ],
          "taxonomy": "",
          "allow_null": 1,
          "multiple": 0,
          "return_format": "object",
          "ui": 1
      }

    What we would like to have is the option to load on of the latest x posts at random.

    I looked at https://support.advancedcustomfields.com/forums/topic/using-acf-to-create-randomized-ad-block/ and array_rand seems to be useful to load at random from an array of posts.

    But how would we do that with the post object choice?

  • Solved

    Pagination on custom WP_query

    Hello
    I asked the forum for help yesterday. That was nice to have a response 🙂
    Read this one : https://support.advancedcustomfields.com/forums/topic/wp_query-checkbox-array-string-error/

    Today I have another problem on this WP query with pagination
    I had this code

    			$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
          $args = array(
            'post_type' => 'post',
            'posts_per_page' => 2,
    				'paged'          => $paged,
            'tax_query' => array(
              array(
                'taxonomy' => $qobjet->taxonomy,
                'field' => 'id',
                'terms' => $qobjet->term_id,
              ),
            ),
            'meta_query' => $meta_query
          );
    
     $query = new WP_Query($args);

    and this code for pagination
    wp_pagenavi( array( 'query' => $query ) );

    This URL is ok
    http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/?genre=femme&minprice=&maxprice=&passion%5B%5D=animaux

    This one (page 2) give me a 404
    http://localhost/ajr2/cadeaux/cadeaux-anniversaire-femme/page/2/?genre=femme&minprice&maxprice&passion%5B0%5D=animaux

    How to fix that ?

  • Solved

    WP_Query checkbox array string error

    Hello,
    I try to build a form for my visitor to allow “filter” post. I have 2 fields with price and 1 with checkbox.

    Now that’s work but it’s too restrictiv. I have 3 checkbox with value “decoration”, “sport”, “jeux”. When I checked one it’s that’s return the right post. When I check 2 or more this return only post the values I want all the post with only 1 value correct not specially too.

    Exemple
    Post 1 = decoration, sport
    Post 2 = decoration, jeux
    Post 3 = jeux

    If I checked decoration
    Return Post 1 and 2 ok

    If I checked decoration and jeux
    Return Post 2 but I want numbers 2 and 3. I think it’s maybe a compare problem ?

    My code

    <form action=" <?php $term_link; ?>" method="get">
        <label>min:</label>
        <input type="number" name="minprice" value="<?php echo $minprice; ?>">
        <label>max:</label>
        <input type="number" name="maxprice" value="<?php echo $maxprice; ?>">
    
        <label>Hobbies:</label>
        <div>
         <p><input type="checkbox" id="aimerparlapersonne" name="passion[]" value="decoration">Décoration</p>
         <p><input type="checkbox" id="aimerparlapersonne" name="passion[]" value="sport">Sport</p>
         <p><input type="checkbox" id="aimerparlapersonne" name="passion[]" value="jeux">Jeux</p>
        </div>
    
        <button type="submit" name="">Filter</button>
    </form>
    
         <?php
                if($_GET['minprice'] && !empty($_GET['minprice']))
                {
                    $minprice = $_GET['minprice'];
                } else {
                    $minprice = 0;
                }
    
                if($_GET['maxprice'] && !empty($_GET['maxprice']))
                {
                    $maxprice = $_GET['maxprice'];
                } else {
                    $maxprice = 999999;
                }
    
                if($_GET['passion'] && !empty($_GET['passion']))
                 {
                     $passion = $_GET['passion'];
    
                     // Get the selected options
                    $meta_query = array('passion' => 'OR');
                     foreach((array) $passion as $passions){
                       $meta_query[] = array(
                           'key'     => 'aimerparlapersonne',
                           'value'   => $passions,
                           'compare' => 'LIKE',
                       );
                    }
                 }
    
                ?>
    
    <?php
           $qobjet = get_queried_object();
           $args = array(
                   'post_type' => 'post'
                   'posts_per_page' => 20	,
                   'tax_query' => array(
                                      array(
                                        'taxonomy' => $qobjet->taxonomy,
                                        'field' => 'id',
                                        'terms' => $qobjet->term_id,
                                          ),
                                        ),
                    'relation' => 'AND',
                    'meta_query' => array(
                                       array(
                                           'key' => 'prix',
                                           'type' => 'NUMERIC',
                                           'value' => array($minprice, $maxprice),
                                           'compare' => 'BETWEEN'
                                       ),
    
                     'meta_query' => $meta_query,
                                    ),
                        );
    
            $query = new WP_Query($args);?>
           <?php if ($query->have_posts() ) : while ($query->have_posts() ) : $query->	the_post(); // run the loop ?>
           <?php get_template_part( 'content-category', get_post_format() ); ?>
           <?php endwhile; ?>
         <?php endif;?>
     <?php wp_reset_query();?>
  • Helping

    ACF Panel in another location positioned only on one user

    Hello to all,

    after having exhausted all the resources where you should be able to locate the option to reset the position of a panel, I have decided to ask it here in the hope of getting a solution.

    A few years ago I created a website managed by several people, two days ago, one of them told me that after a change he made on the website, the panel created with ACF for a specific taxonomy and the YOAST panel, which are usually at the bottom, is now located in the editor tools panel, along with the post image, permalink, etc… I thought I had made some change in the ACF configuration, but when I logged in I saw that the only admin is me and the others are editors, a role that is quite limited. Does anyone have any idea how a user can make this modification without sufficient privileges and without having access to the code (in this there have been no changes, I have the project linked locally)?

    I can remove some custom panels from the sidebar of the post and put them under the editor, but I can’t reposition them.

    Thank everyone

  • Solving

    ACF image Taxonomy term in Elementor

    Hi,
    I have a Country taxonomy then set a ACF image FLAG for each county.
    In a elementor loop i try to display with a shorcode but this returns nothing, is it normal ?
    $image = get_field('flag', 'country' . '_' . get_the_ID());
    thanks

  • Solved

    Get Field from Custom Post Typ

    I currently have

    <?php 
    
    // Variables
    $number_of_events = get_field( 'number_of_events' );
    // print_r($number_of_events);
    $event_categories = get_field('event_categories');
    $event_cat_ids = wp_list_pluck( $event_categories, 'term_id' );
    
    $args = array(
    		'post_type' 		=> 'event',
    		'post_status'		=> 'publish',
    		'posts_per_page'	=> $number_of_events,
    		'order'				=> 'DESC',
    );
    			
    $args['tax_query'] = array(
    	'relation' 		=> 'OR', 
    
    	array(
    		'taxonomy'	=> 'event_category',
    		'field'		=> 'term_id',
    		'terms'		=> $event_cat_ids
    	),			
    		
    );
    
    $query = new WP_Query( $args );
    if( $query->have_posts() ) : ?> 
    	<div class="event-grid">
    		<?php while( $query->have_posts() ): $query->the_post();
    		// $date_number = get_field('date_number');
    		// $date_number = get_field('date_and_time');
    		// $event_title = get_field('event_title');
    		// $event_location = get_field('event_location');
    		// $event_description = get_field('event_description'); 
    		?>
    			<div class="block-box event-box">
    				<div class="event-number-container">
    					<p class="event-number">date<?php //echo $date_number; ?></p>
    				</div>
    				<div class="event-details">
    					<p class="event-date-time"><?php the_field('date_and_time' ?></p>
    					<h4 class="event-title"><?php the_title(); ?></h4>
    					<p class="event-location">event location<?php // echo $event_location; ?></p>
    				</div>
    			</div>
    		<?php endwhile;  wp_reset_postdata();
    endif;
    ?>

    but I want to get the field date_and_time which I attached to object events. How do I take care of this? Tried adding the term, and grabbing it using

    $term = get_queried_object();
    $date_and_time = get_field('date_and_time', $term);

    but no luck yet somehow..

Viewing 25 results - 326 through 350 (of 3,191 total)