Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

topic

  • Helping

    filter posts by category

    In my flexible content group, I have a layout (vendors) in order to display a list on the front end.

    In my script, I’m currently using the following query:

    query_posts(array(
    ‘post_type’ => ‘vendors’,
    ‘numberposts’ => 100,
    ‘posts_per_page’ => 100,
    ‘orderby’ => ‘menu_order’,
    ‘order’ => ‘ASC’,
    ‘post__not_in’ => array(
    get_the_ID()
    ),
    ));

    I’m wanting to add the functionality to filter the list based on categories using the “taxonomy” field type, so I added a field to the layout (“categories”).

    If I hard code this to the query:

    ‘category__and’ => array(5),

    it will display only those vendors assigned to the category id 5.

    What I want is to be able to assign the categories based on the selection in the flexible content. I figured something like this would work:

    first

    category__and’ => array(get_sub_field(‘categories’)),

    but it does not. How can I fix this?

    Appreciate the help.

    (not an expert in PHP, obviously, so please go easy! Thx)

  • Solving

    Save Terms and Load Terms not Working for ACF Blocks for the Taxonomy field type

    I have created a block which has a field where the user can select a term from a custom taxonomy, multiple terms from that taxonomy or create a new term.
    I have set the UI to false for the taxonomy so it doesn’t show on the custom post type as default WordPress metabox.
    The selection works Ok, but there are two options that do not work:
    Save Terms and Load Terms.

    I am guessing that this has to do something with the field being added to a block which is not directly a post type. But will be good to work when the block is added on a custom post type that supports that specific taxonomy.

  • Solved

    Custom image field inside product_cat taxonomy not displaying

    So, I have created a custom field inside my product categories for an image to be uploaded (I am using both the standard WP category image, as well as this second one). I need to display the field inside a loop, but am having trouble getting it to show.

    <div class="product-categories-list">
       <?php foreach( $prod_categories as $prod_cat ) {     
         $cat_thumb_id = get_term_meta( $prod_cat->term_id, 'thumbnail_id', true );
         $shop_catalog_img = wp_get_attachment_image_src( $cat_thumb_id, 'large' );
         $term_link = get_term_link( $prod_cat, 'product_cat' );
         $cat_title = $prod_cat->name; 
    
         // THIS FIELD
         $cat_term = get_queried_object();
         $hover_img = get_field('hover_image', $cat_term); 
       ?>
    
              <div class="product-category">
                <a href="<?php echo $term_link; ?>">
                  <div class="image">
                    <img class="base-image" src="<?php echo $shop_catalog_img[0]; ?>" alt="<?php echo $cat_title; ?>" />
                    <img class="hover-image" src="<?php echo $hover_img['url']; ?>" alt="<?php echo $cat_title; ?>">
                  </div>
                  <h3><?php echo $cat_title; ?></h3>
                </a>
              </div>
              
            <?php } wp_reset_query();?>
            </div>
  • Solving

    Custom post query with multiple fields with number values. Totalisation needed

    The following code gives me several tables (sorted by category) with custom fields and number values. What I need now, is a totalisation at the end of every table. How can I do that? Thanks!

    <div class="togglecontent"> <?php
    $portraetrangliste = get_the_id();
    
      $catargs = array(
             'taxonomy'     => 'jahr',
            'order' => 'DESC',
      );
    $cats = get_categories($catargs);
    
    foreach ($cats as $cat) {
    $args = array(
            'posts_per_page' => -1,
        'post_type'     => 'rangliste',
        'meta_key'      => 'portrait_nid',
            'order' => 'DESC',
            'orderby' => 'date',
            'post_status' => 'publish',
        'meta_value'    =>  $portraetrangliste,
    'tax_query' => array(
        array(
            'taxonomy' => 'jahr',
            'field'    => 'term_id',
            'terms'    => $cat->cat_ID,
            ),
        ),
    );
    global $post;
    $query = new WP_Query($args);
    if ( $query->have_posts() ): ?> <h5>Saison <?php echo $cat->cat_name ; ?> </h5>
      <table class="portraetrangliste">
        <tr>
          <th>Rang</th>
          <th>Kranz</th>
          <th>Sieger</th>
          <th>Jahreswertung<br />Punkte</th>
          <th>Bezwungene <br /> Eidgenossen </th>
          <th>Datum / Fest</th>
        </tr> <?php
    
       while($query -> have_posts()) : $query -> the_post(); ?> <tr>
          <td>
            <strong> <?php the_field( 'rang' ); ?> </strong>
          </td>
          <td> <?php if ( get_field( 'kranzgewinn' ) == 1 ) : ?> <?php echo 'Ja'; ?> <?php else : ?> <?php echo 'Nein'; ?> <?php endif; ?> </td>
          <td> <?php if ( get_field( 'sieger' ) == 1 ) : ?> <?php echo 'Ja'; ?> <?php else : ?> <?php echo 'Nein'; ?> <?php endif; ?> </td>
          <td> <?php the_field( 'punkte_jahresliste' ); ?> </td>
          <td> <?php the_field( 'bezwungene_eidgenossen' ); ?> </td>
          <td> <?php global $post; ?> <?php $fest_nid = get_field( 'fest_nid' ); ?> <?php if ( $fest_nid) : ?> <?php $post = $fest_nid; ?> <?php setup_postdata( $post ); ?> <?php echo get_the_date('d.m.Y'); ?> - <a href="
                        
                        
                        <?php the_permalink(); ?>"> <?php the_title(); ?> </a> <?php wp_reset_postdata(); ?> <?php endif; ?> </td>
        </tr> <?php
       endwhile; ?>
      </table> 
     <?php endif; 
    
    // Added this now 
    wp_reset_query() ; 
    }
    ?></div>
  • Solved

    How to allow user to filter post object field by category ?

    Hello !

    I have a ‘downloads’ custom post type and users can select files with ACF post object field

    However there are many files, and they do have a custom taxonomy associated with it

    Is there a way for users to select from which category they select files from ? Thanks

  • Helping

    Get category slug name out of Taxonomy field

    I m trying to get the category slug name out of a Taxonomy ACF field “Category” and return its value inside an array which will help me display Latest Posts from selected Category.

    
    $catName = get_field('latest_news_category');
    
                $args = array(
                    'post_type'         => array('post'),
                    'post_status'       => array('publish'),
                    'category_name'     => $catName,
                    'posts_per_page'    => '3',
                    'orderby'           => 'date',
                    'order'             => 'DESC',
                );
  • Solved

    Filter get_field results?

    I have a relationship built between two different post types: 1. Furniture (furniture); 2. Fabrics & Finishes (fabricsandfinishes).

    Fabrics & Finishes has a custom taxonomy attached to it called “Options”.

    On the single Furniture page, I need to display the swatches from Fabrics & Finishes. I’ve got it working according to the documentation and they’re displaying correctly.

    <?php 
    
    						$swatches = get_field('furniture_swatches');
    
    						?>
    						<?php if( $swatches ): ?>
    							<ul>
    							<?php foreach( $swatches as $swatch ): ?>
    								<li>
    										<?php echo get_the_post_thumbnail( $swatch->ID );
                        ?>
    									</a>
    								</li>
    							<?php endforeach; ?>
    							</ul>
    						<?php endif; ?>

    However, I need to separate the swatches by their taxonomy on the single Furniture page (e.g.—Standard Frames Swatches[][][][][][], Premium Frames[][][][], Awning Fabrics[][][][][][][], ect.)

    I’ve done a lot of searching, but any advice on how to achieve this would be very helpful. Thanks!

  • Solving

    Get Total of Matching Fields in Repeater Within Custom Query

    Hey everyone!

    I’m setting up a site and have run into a wall. I have three custom post types: clients, flowers, hard_goods. The ACF set up is the following: Wedding Date (date picker), Flowers Count List (field name:’flowers_count_list’ – Repeater) that contains Flowers (field name: ‘flowers’ – relationship to cpt of flowers) and Flowers Count (field name: ‘flowers_count’ – number used per client). I have the archive page set up to display posts within a date range but I’m looking to get a total of the ‘flowers_count’ matching flowers by their name ‘flowers’ then a breakdown by wedding underneath that, all in alphabetical order.

    Example:
    Delilah: 12

    • Client 2 – 6 Delilah
    • Client 4 – 4 Delilah
    • Client 5 – 2 Delilah

    Roses: 5

    • Client 1 – 3 Roses
    • Client 2 – 2 Roses

    Tulips: 15

    • Client 3 – 10 Tulips
    • Client 5 – 5 Tulips

    Here’s the code I currently have that’s showing the individual breakdown by client.

    
    add_action('wp_ajax_myfilter', 'misha_filter_function'); // wp_ajax_{ACTION HERE} 
    add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');
    
    function misha_filter_function(){
        $args = array(
            'post_type'         => 'clients',
            'meta_key'          => 'wedding_date',
            'orderby'           => 'meta_value',
            'order' => $_POST['date'] // ASC or DESC
        );
     
        // for taxonomies / categories
        if( isset( $_POST['categoryfilter'] ) )
            $args['tax_query'] = array(
                array(
                    'taxonomy' => 'category',
                    'field' => 'id',
                    'terms' => $_POST['categoryfilter']
                )
            );
     
        // create $args['meta_query'] array if one of the following fields is filled
        if( isset( $_POST['start_date'] ) && $_POST['start_date'] || isset( $_POST['end_date'] ) && $_POST['end_date'] || isset( $_POST['featured_image'] ) && $_POST['featured_image'] == 'on' )
            $args['meta_query'] = array( 'relation'=>'AND' ); // AND means that all conditions of meta_query should be true
     
        // if both minimum price and maximum price are specified we will use BETWEEN comparison
        if( isset( $_POST['start_date'] ) && $_POST['start_date'] && isset( $_POST['end_date'] ) && $_POST['end_date'] ) {
            $args['meta_query'][] = array(
                'key' => 'wedding_date',
                'value' => array( $_POST['start_date'], $_POST['end_date'] ),
                'type' => 'date',
                'compare' => 'between'
            );
        } else {
            // if only min price is set
            if( isset( $_POST['start_date'] ) && $_POST['start_date'] )
                $args['meta_query'][] = array(
                    'key' => 'wedding_date',
                    'value' => $_POST['start_date'],
                    'type' => 'date',
                    'compare' => '>'
                );
     
            // if only max price is set
            if( isset( $_POST['end_date'] ) && $_POST['end_date'] )
                $args['meta_query'][] = array(
                    'key' => 'wedding_date',
                    'value' => $_POST['end_date'],
                    'type' => 'date',
                    'compare' => '<'
                );
        }
    
     
        // if post thumbnail is set
        if( isset( $_POST['featured_image'] ) && $_POST['featured_image'] == 'on' )
            $args['meta_query'][] = array(
                'key' => '_thumbnail_id',
                'compare' => 'EXISTS'
            );
        // if you want to use multiple checkboxed, just duplicate the above 5 lines for each checkbox
     
        $query = new WP_Query( $args );
        
        if( $query->have_posts() ) :
    
        echo '<div class="wedding-clients-gallery">';
    
        while( $query->have_posts() ): $query->the_post();
    
                echo '<div class="client-wedding"><a href="';
                    the_permalink();
                echo '"><h2>';
                the_title();
                echo '</h2></a> date: ';
                the_field('wedding_date');
    
        // Check rows exists.
        if( have_rows('flowers_count_list') ):
        
        echo '<h3>Flowers List:</h3>';
    
            // Loop through rows.
            while( have_rows('flowers_count_list') ) : the_row();
    
        $featured_posts = get_sub_field('flowers');
    
        if( $featured_posts ): ?>
        <ul>
        <?php foreach( $featured_posts as $post ): 
    
            // Setup this post for WP functions (variable must be named $post).
            setup_postdata($post); ?>
            <li>
                <?php
                echo get_the_title( $post->ID );
                echo '( ';
                the_sub_field('flowers_count');
                echo ' )';
                ?>
            </li>
        <?php endforeach; ?>
        </ul>
        <?php 
        // Reset the global post object so that the rest of the page works correctly.
        wp_reset_postdata();
    
        endif;
            // End loop.
            endwhile;
    
            // No value.
            else :
                // Do something...
            endif;
    
    // Check rows exists.
        if( have_rows('hard_goods_count_list') ):
        
        echo '<h3>Hard Goods List:</h3>';
    
            // Loop through rows.
            while( have_rows('hard_goods_count_list') ) : the_row();
    
        $featured_posts = get_sub_field('hard_goods');
    
        if( $featured_posts ): ?>
        <ul>
        <?php foreach( $featured_posts as $post ): 
    
            // Setup this post for WP functions (variable must be named $post).
            setup_postdata($post); ?>
            <li>
    
                <?php
                echo get_the_title( $post->ID );
                echo '( ';
                the_sub_field('hard_goods_count');
                echo ' )';
                ?>
            </li>
        <?php endforeach; ?>
        </ul>
        <?php 
        // Reset the global post object so that the rest of the page works correctly.
        wp_reset_postdata();
    
        endif;
            // End loop.
            endwhile;
    
            // No value.
            else :
                // Do something...
            endif;
    
                echo '</div>';
            endwhile;
    
            echo '</div>';
    
            wp_reset_postdata();
        else :
            echo 'No posts found';
        endif;
        
        die();
    }
    

    Thank you for reading through this and the potential help!

  • Solved

    Query posts for a relationship value fallback issues

    Hi,

    I am using the meta_query LIKE to match an author value “Joe Blogs” to the database value stored on in a relationship field, however If there is no match within the LIKE comparison, the meta_query still produces a wild card result similar to if the comparison condition was not set at all.

    If am trying to find a possible solution that if no result is provided from the meta_query then it would fall back to a tax_query so as a result wold always be possible.

    
    $articles = new WP_Query(
        array(
            'post_type' => 'article',
            'orderby' => 'posted_date',
            'order' => 'DESC',
            'post_status' => 'publish',
            'posts_per_page' => $totalRecordsToDisplay,
            'meta_query' => array (
                array(
                    'key' => 'authors', // relationship field
                    'value' => '"' . get_the_ID() . '"',
                    //'value' => $post->post_title,
                    //'value' => get_the_id(),
                    'compare' => 'LIKE'
                )
                    
    
            ),
            'tax_query' => array(
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'expertise',
                        'field' => 'term_id',
                        'terms' => array(join(",", wp_list_pluck($expertises, 'term_id'))),
                        'include_children' => true
                    )
                )
            ),
    
        )
    );
    
  • Helping

    Query posts for a relationship value fallback issues

    Hi,

    I am using the meta_query LIKE to match an author value “Joe Blogs” to the database value stored on in a relationship field, however If there is no match within the LIKE comparison, the meta_query still produces a wild card result similar to if the comparison condition was not set at all.

    If am trying to find a possible solution that if no result is provided from the meta_query then it would fall back to a tax_query so as a result wold always be possible.

    
    $articles = new WP_Query(
        array(
            'post_type' => 'article',
            'orderby' => 'posted_date',
            'order' => 'DESC',
            'post_status' => 'publish',
            'posts_per_page' => $totalRecordsToDisplay,
            'meta_query' => array (
                array(
                    'key' => 'authors', // relationship field
                    'value' => '"' . get_the_ID() . '"',
                    //'value' => $post->post_title,
                    //'value' => get_the_id(),
                    'compare' => 'LIKE'
                )
                    
    
            ),
            'tax_query' => array(
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'expertise',
                        'field' => 'term_id',
                        'terms' => array(join(",", wp_list_pluck($expertises, 'term_id'))),
                        'include_children' => true
                    )
                )
            ),
    
        )
    );
    
  • Solving

    Rename and relocate uploaded Images

    @hube2 esp.,

    Concerning these previous threads…

    … I had wanted to take an image uploaded to an ACF Image field, then a) move it to a specific sub-folder and b) rename it.

    I took my learnings from these threads and other online info and worked up some code. I kept this code in a dedicated plugin.

    But that code was designed to work only on an Edit-User page – that is, when a user uploads an Image to whilst on user-edit.php or profile.php, a) relocate it to a sub-folder of uploads, users/avatars, then b) rename it as the user slug dot extension.

    I had also made a separate version of this plugin to run on the Edit Term (term.php) page for a custom taxonomy (Company) – ie. rename the image to termslug.ext and relocate to /wp-content/uploads/companies/logos. This worked, too – until this week, though that’s not the nub of my post…

    See the plugins I just posted on GitHub FYI (cxt-wp-user-avatar, cxt-wp-tax-company-logo – but, really speaking, the first one, which actually functions currently).

    The trouble is, I can see reason for consolidation…

    Right now, each plugin carries hard-coded settings variables for the relevant ACF field, new-name composition and destination to which to move the renamed file.

    That’s not flexible, either for the multiple use cases I may have for this type of thing or for other people who may want to use such code.

    Both variants of this code do basically the same thing – take an uploaded ACF Image file, rename it according to the slug/name of the current WP “object” (user, taxonomy term) and move it under a corresponding sub-folder of uploads.

    I even have a third instance of this task I want to budget for – performing the same on a second Company term Image field, “favicon”.

    Do you have any thoughts on how I could achieve consolidation – that is, using one flexible plugin/method that can align the basic function here for all scenarios?

    The core purpose here is basically Media Library / image folder management efficiency/automation. It’s sort of something I maybe feel should be baked in to WP but isn’t, so I see room for an extension.

    Thoughts…

    * Applicability to all ACF Image fields?

    * Achievability of doing so. ie given the number of pages on which an Image field could be placed, is it possible for code to find and use a “slug” or equivalent in every case?

    * How to identify the field key and field name automatically? Currently these are hard-coded, needed to be known in advance. Can this requirement be removed?

    * How to identify corresponding sub-folders, if removing the requirement for pre-known location settings? eg. Should they follow a standard sub-folder naming convention, eg. /wp-content/uploads/{object}/{fieldname} (/wp-content/uploads/{user}/{avatar}/{username.ext} but also /wp-content/uploads/{taxonomy}/{company}/{logo}/{term.ext}?

    * Would one really want this to apply to all ACF Image fields, or only some?

    * Extent to which this is an ACF thing vs WP.

    PS. I am a git and GitHub newbie. I’m trying to learn some proper development and version control practices, and to be able to store code like this in repositories for pulling down to multiple sites. Also trying to put the code out in public a little. Please feel free to let me know if I should be doing anything differently here, including on attribution.

    Thanks.

  • Solving

    Frontend Form with Taxonomy field that can create terms

    Hi,

    I’m looking for a way to include a taxonomy field into a frontend-facing form where users have the possibility (among other fields) to not only select matching taxonomy terms but create new ones at the same time, just like the wp-admin taxonomy field provides. Can anyone point me into the direction of a solution?

    Thanks,
    Daniel

  • Solved

    Books & authors – bidirectional relationship or custom taxonomy?

    Hi,

    I have a conceptual question. Think about the example books and authors. I made a webshop that sells books. BOOKS (WooCommerce products) have different attributes for description and filtering.

    They also have a bidirectional relationship with AUTHORS. So there is also the CPT author, that also comes with some fields and images to describe them.

    Now, I realize I could also create a custom taxonomy for the WooCommerce product (book). I was not aware that I can add custom fields to a custom taxonomy, i.e. it will server like a category but at the same time describe the category in more detail with custom fields.

    I am asking myself now: would it be better to assign the custom taxonomy to the books, instead of creating a separate CPT author and bidirectional relationship?

    (actually, it’s composers and musical pieces but easier to comprehend with books and authors)

    best regards
    Markus

  • Helping

    How do I use tax_query and meta_query together?

    I’ve got a custom post type called ‘lawyer’ with a taxonomy called ‘city_taxonomy’,
    I’m trying to display a list of jobs with a certain tax term [city 1] with (11) , and have acf multi select field his name [service-type] have items (item1, item2 , item3, item4)
    i want to display posts with term 10 and select value item2 ,item3

    <?php
    $args = array(
    ‘post_type’ => ‘lawyer’,
    ‘posts_per_page’ => -1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘city_taxonomy’,
    ‘field’ => ‘id’,
    ‘terms’ => 11,
    ),
    ),

    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘service-type’,
    ‘value’ => array(‘item2′,’item3’),
    ‘compare’ => ‘IN’,
    ),
    ),

    );
    print_r($args);
    $loop = new WP_Query($args);
    if ($loop->have_posts()) : ?>
    <?php while ($loop->have_posts()) : $loop->the_post(); ?>
    <?php the_title(); ?>
    <?php endwhile; endif; ?>

  • Helping

    Best practice for taxonomy description field

    I see that taxonomies have a default description field with comment:

    The description is not prominent by default; however, some themes may show it.

    I have added my own detailed description WYSIWYG field but I was wondering what best practices are for using the default description field? I feel that I should put something in that field since it is available.

  • Solved

    2 select parent the child taxonomy acf

    Hi
    I use acf pro
    Iuse this form:
    https://ophthoplus.com/staging/1967/atlas-photo-form/
    Ihave 2 multiselect(same taxonomy)
    Iwant when choosing from type (yhe parent taconomy)
    Then in diagnosis (child taxonomy) display specific from parent Taxonomy.
    How can do it?

  • Helping

    Can ACF taxonomy fields be used by Elementor?

    A very basic question I think… I have created a custom taxonomy and added 2 fields to that taxonomy in CPT.

    In Elementor I can select those ACF fields but nothing shows up.

    So is this not possible without code?

  • Solving

    Ajax Filtering of Google Maps

    Hi All,

    Ok, so I’m having to admit defeat and could really do with some help.

    I’ve a CPT of locations and a Taxonomy of type

    Each location can enter an address (google map field) and select a type.

    A very basic page displays all the locations and the taxonomies:

    <article class="container-fluid py-5" id="locations">
    <?php
    global $wp_query;
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array(
    	'posts_per_page' => 12,
    	'post_type'		=> 'locations',
    	'paged' 		=> $paged
    );
    $wp_query = new WP_Query($args); ?>
    <?php if ($wp_query->have_posts()) : ?>
    <?php $total_reviews = $wp_query->found_posts; ?>
    <div class="container">		
    	<div class="row">
    		<div class="col-12"  id="filters">
    	<?php 
    	$types = get_terms(array(
    		'taxonomy'	 => 'type',
    		'orderby'	 => 'term_order',
    		'hide_empty' => false
    	));
    	foreach ($types as $type): ?>
    	<a class="btn btn-primary mr-2 mb-4" href="#" typeid="<?php echo $type->term_id; ?>"><?php echo $type->name; ?></a><br/>		
    	<?php endforeach; ?>
    		</div><!-- /col-md-8 -->	
    	</div><!-- /row -->			
    	<div class="row">
    		<div class="col-12">
    		
    			<p class="filter_status">
    
    			<div class="acf-map" data-zoom="16" id="ajax_filter_locations">
    			<?php while ($wp_query->have_posts()) : $wp_query->the_post(); $address = get_field('address'); ?>
    				<?php include( locate_template( 'includes/loop.php', false, false ) ); ?>
    			<?php endwhile;  ?> 
    			</div><!-- /acf-map -->
    
    		</div><!-- /col-md-8 -->	
    	</div><!-- /row -->
    </div><!-- /container -->     
    <?php endif; wp_reset_query(); ?> 
    </article><!-- /container -->

    This works fine (basic for testing purposes).

    I’ve got my js file:

    //filter the locations
    jQuery(function($){			
    
    	jQuery('#filters .btn').click(function(){
    	
    		var typeid = jQuery(this).attr("typeid");
    		//alert('typeid: '+typeid);
    
    		jQuery.ajax({
    			type        : "POST",
    			data		: { action: 'get_location_posts', typeid: typeid}, 
    			dataType	: "html",
    			url : 		myAjax.ajaxurl,			
    
    			beforeSend	: function(xhr){
    				jQuery("#filters").find('p.font-weight-bold').text('Filtering...');
    			},				
    			success     : function(data) {
    				//alert(this.data);	
    				jQuery("#ajax_filter_locations").html(data);
    				//console.log("success! typeid: " + typeid);	
    				},
    			error       : function(xhr, status, error) {
    				var err = eval("(" + xhr.responseText + ")");
    				alert(err.err);
    			}
    		});
    		return false;
    	});	
    			
    });

    I then have the following code in my functions file to handle the filtering:

    function get_location_posts() {
    	
    	$typeid = $_POST['typeid'];
    	
    	#$page = $_POST['page'];
    	
    	$paged = get_query_var('paged') ? get_query_var('paged') : 1;
    	
    	$args = array(
    			'post_type' 		=> 'locations',
    			'post_status'		=> 'publish',
    			'posts_per_page'	=> -1,
    			'order'				=> 'DESC',
    			#'paged' 			=> $page,	
    	);
    			
    	if( !empty( $_POST['typeid'] ) ){
    		$args['tax_query'] = array(
    			'relation' 		=> 'OR', 
    
    			array(
    				'taxonomy'	=> 'type',
    				'field'		=> 'term_id',
    				'terms'		=> $typeid
    			),			
    
    		);
    	}
    	
    	$query = new WP_Query( $args );
    	if( $query->have_posts() ) : 
    		echo '<div class="acf-map" data-zoom="16">';
    		while( $query->have_posts() ): $query->the_post();	
    			include( locate_template( 'includes/loop.php', false, false ) );
    		endwhile;  wp_reset_postdata();
    		echo '</div><!-- /acf-map -->';
    	else:
    	
    		echo '<div class="col-12 text-center">';
    		echo '<p class="text-center font-weight-bold lead">Sorry, no Locations available for this rating.
    ';
    		echo '</div><!-- /col-12 -->';
    	
    	endif;
    	
    	die();
    
    }
    // Fire AJAX action for both logged in and non-logged in users
    add_action('wp_ajax_get_location_posts', 'get_location_posts');
    add_action('wp_ajax_nopriv_get_location_posts', 'get_location_posts');

    All files load etc.

    loop.php contains the info for each location.

    Now, the map loads initially and shows the various locations. The issue is when you try to filter. The map disappears and the relevant locations load as a list.

    I’ve tried adding the map wrapper in the ajax return:
    <div class="acf-map" data-zoom="16">
    I’ve removed it but still can’t get this working

    So it seems like I somehow need to reinstate the map. I wonder if it’s this:
    google.maps.event.trigger(map, 'resize');

    But Googling round, apparently this is no longer relevant.

    Has anyone else managed to sort this? I’ve found some really old examples but they don’t work with the newer map versions.

    Any help would be very much appreciated!

  • Solving

    User taxonomy – displaying filtered list in admin

    I’m using ACF PRO to create user taxonomy fields. I have selected “Save Terms” and “Load Terms” in the field. I can select categories fine, and the count for number of users that have a given category shows in the category admin page (created with code below). However, if I click on the count, no users(posts) are displayed. What have I missed?

    I have been using various guides to help me setup categories, and have stripped out what I though ACF was doing for me.

    /**
     * Creat custom taxonomies.
     */
    add_action( 'init', 'mw_create_custom_tax' );
    
    function mw_create_custom_tax() {
    	register_taxonomy(
    		'interests',
    		array('user'),
    		array(
    			'label' => __( 'Interests' ),
    			'hierarchical' => true,
    			'public'       => true,
    		)
    	);
    }
    
    /* Adds the taxonomy page in the admin. */
    add_action( 'admin_menu', 'mw_add_interests_admin_page' );
    
    function mw_add_interests_admin_page() {
    
    	$tax = get_taxonomy( 'interests' );
    
    	add_users_page(
    		esc_attr( $tax->labels->menu_name ),
    		esc_attr( $tax->labels->menu_name ),
    		$tax->cap->manage_terms,
    		'edit-tags.php?taxonomy=' . $tax->name
    	);
    }
    
    function mw_set_interests_category_submenu_active( $submenu_file ) {
    	global $parent_file;
    	if( 'edit-tags.php?taxonomy=' . 'interests' == $submenu_file ) {
    		$parent_file = 'users.php';
    	}
    	return $submenu_file;
    }
  • Solving

    acf/fields/post_object/query inside repeater filtered by taxonomy sub_field

    I have a repeater field “Rankings” with taxonomy field ‘School’ and Post object field ‘Courses’
    Can I use acf/fields/post_object/query to filter the Courses by chosen School? If yes, how should I go about it? Any resources, documentation or related discussions links are appreciated!

  • Solved

    Getting ACF field from a taxonomy in a page with WP_query

    Hi there,

    I’m stuck with this. I’m trying to get the ACF field image ‘logo_marque’ that I used for the taxonomy ‘marques-produit’ from my CPT ‘produits’ on my front page.

    I’m using this code :

    					<?php 
    						$logo = get_field('logo_marque');
    						$args = array( 
    						'post_type' => 'produits', 
    						'tax_query' => array(
    							array (
    								'taxonomy' => 'marques-produits',
    								'fields' => $logo,
    							)
    						),
    						'posts_per_page' => -1, 
    						'order' => 'DESC' );
    						$loop = new WP_Query( $args );
    						while ( $loop->have_posts() ) : $loop->the_post(); ?>
    						<div class="product">
    
    						<img src="<?php echo esc_url($logo['url']); ?>" alt="<?php echo esc_attr($logo['alt']); ?>" />
    						</div>
    						<?php endwhile; ?>
    					<?php wp_reset_query(); ?>    
    

    Thank you for your help.

  • Unread

    load values and labels from custom taxonomy select field

    Hi,
    I’m trying to load different labels to the taxonomy select field (admin back-end only) but with no luck. The values are returning as default, $term->name only.
    With filter acf/fields/taxonomy/result the same with changed the first 2 character:
    {“results”:[{“id”:81,”text”:”A?ycustomlabel:…….

    
    function render_component_field($field) {
    	
        $field['results'] = array();
    
        $args = array(
            'taxonomy'   => 'call_components',
    		'hide_empty' => false
        );
        $terms = get_terms( $args );
    
        foreach($terms as $term) {
            $cid = get_field( 'cid', 'call_components_'.$term->term_id );
            $list[$term->term_id] = $cid.' '.$term->name;
        }
    	
        $field['choices'] = $list;
        return $field;
    	
    }
    add_filter('acf/load_field/name=component', 'render_component_field');
    

    Any help would appreciated.

  • Solving

    The updated field is not refreshed

    Hello,

    After a custom post type is saved, I hook on the action “acf/save_post” so I can create a category with the post name, then I update a taxonomy field of the custom post type with the id of this category.
    When I clic on publish the post, the taxonomy field ( a select) is still empty. But If I check the database, it is filled correctly. So I refresh the page, and now the taxonomy field is displaying the correct value in the dropdown.

    My code in functions.php :

    add_action('acf/save_post', 'save_commune');
    function save_commune( $post_id ) {
        global $post; 
        $cat_id = wp_create_category( $post->post_title, 0 );
        update_field('cat_id', $cat_id, $post_id );
    }

    Any ideas on how I can see a correctly displayed field after publishing a post without refreshing the whole page manually ?

  • Solving

    Filter Taxonomy Field by Custom Field

    I have a taxonomy field for Categories and have added a custom field to the category called “Premium”. I would like my category ACF field to just show the Premium categories. I’m not sure how to approach that. I don’t see a way to filter the category in the taxonomy field.

    Thanks in advance.

  • Unread

    ACF Field not inserting user's input after update

    Hello Team,

    Recently we have updated our website to make it secure. But there is issue in which user’s input is not getting in ACF field.

    https://www.??????.co.uk/parent-registration-form/?school=Acklam%20Whin%20Primary%20School

    That ?school parameter insert data in field, which helps to user to redirect to that particular page.

    Field Settings : https://ibb.co/tp7V7ft

    function acf_load_school_permission_field_choices( $field ) {
        
        // reset choices
        $field['choices'] = array();
        
        $choices = array();
        // get the textarea value from options page without any formatting
        $choices_arr = get_terms(
          array(
            'taxonomy' => 'product_cat',
            'orderby' => 'slug',
            'child_of' => 1664,
            'parent' => 1664,
            'hide_empty' => 0));
       // print_r($choices_arr);
    
        foreach ($choices_arr as $choice) {
          array_push($choices, $choice->name);
          
        }
    
        update_field( 'schools_list', 'Steve|two|three' , 49902 );
        //print_r($choices);
    
        
        // explode the value so that each line is a new array piece
        // $choices = explode(",", $choices);
    
        
        // remove any unwanted white space
        $choices = array_map('trim', $choices);
    
        
        // loop through array and add to field 'choices'
        if( is_array($choices) ) {
            
            foreach( $choices as $choice ) {
                
                $field['choices'][ $choice ] = $choice;
                
            }
            
        }
        
    
        // return the field
        return $field;
        
    }
    
    add_filter('acf/load_field/name=school_permission', 'acf_load_school_permission_field_choices');
    add_filter('acf/load_field/name=school_permission_second', 'acf_load_school_permission_field_choices');

    Regards
    Rajat Sharma

Viewing 25 results - 301 through 325 (of 3,191 total)