Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • I discovered the problem. It wasn’t related to ACF, at all.

    I had an error in a pre_get_posts declaration, which was affecting the loop. I was using is_main_query() instead of $query->is_main_query().

    I removed the problematic code, and it works like a charm.

  • 
    // get relationship field without formatting
    // returns an array of post ID values
    $posts_ids = get_field('relationship_field', false, false);
    // do your own query to order the posts
    $args = array(
      'post_type' => 'any',
      'posts_per_page' => -1,
      'post__in' => $post_ids,
      'meta_query' => array(
        'date_clause' => array(
          'key' => 'date_field',
          'value' => 'EXISTS'
        ),
      ),
      'orderby' => array('date_clause' => 'ASC');
    );
    $custom_query = new WP_Query($args);
    if ($custom_query=>have_posts()) {
      while ($custom_query=>have_posts()) {
        $custom_query=>the_post();
        // code continues...
      }
    }
    wp_reset_postdata();
    
  • The WYSIWYG editor works just like the WP main editor. There is nothing in ACF that will let you do this and I don’t think there is anything in WP that will let you do this. If you find something that will work in the main WP editor, it will also work in the ACF field.

    https://wordpress.stackexchange.com/questions/85054/how-to-add-a-class-to-ul-tags-created-by-the-wordpress-editor-tinymce/85071, the last comment is pretty much what I was thinking, having a class on the wrapper element of the ACF output rather than trying to force classes into the editor.

  • $fields = get_field_objects(); requires a post ID, if none is supplied then it returns values for the current post. Exactly what that values is depends on the page it’s running. So, the field in question for the current post in your case only has 2 values. These posts have information on how you can get fields in specific field groups.

    ACF5
    https://support.advancedcustomfields.com/forums/topic/get-all-fields-by-group-id/
    https://support.advancedcustomfields.com/forums/topic/how-to-get-all-acf-groups-or-field-for-specific-post-type/
    https://dream-encode.com/acf-get-all-fields-in-a-field-group/

    ACF4
    https://support.advancedcustomfields.com/forums/topic/get-fields-in-a-group-or-tab-for-output/

  • For me this falls into the same category as ACF repeater sub fields. They make it hard to do queries. See my explanation of how I handle repeater sub fields here. Checkbox, multi-select, repeater sub fields, anything that stores a serialized array can be handled in a similar fashion. https://acfextras.com/dont-query-repeaters/

  • Thanks for posting the solution – even returning an integer has moved me forward a bit.

    I know you are saying your code is full of red herrings relating to your plugin, could you post some of it anyway? – I can’t workout what to do based on this;

    stripped the parent name prefix off the subfields I was able to prepopulate the repeater with my custom table data

    Tantalising. Sorry to be a pain asking for the codez !

    Robbie

  • There is an explanation of how to do this on this page https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ 4. Sub custom fields values and there is a conversation here, the last comment tells you how to fix the example so that it works https://support.advancedcustomfields.com/forums/topic/percentage-in-sql/

    Or you can follow my advice here https://acfextras.com/dont-query-repeaters/

  • Getting same error as everyone else. Can’t update ACF Pro on some sites, while others work using the exact same auth code.

    An error occurred while updating Advanced Custom Fields PRO: Before you can receive product updates, you must first authenticate your Elegant Themes subscription. To do this, you need to enter both your Elegant Themes Username and your Elegant Themes API Key into the Updates Tab in your theme and plugin settings. To locate your API Key, log in to your Elegant Themes account and navigate to the Account > API Key page. Learn more here. If you still get this message, please make sure that your Username and API Key have been entered correctly

    All sites are on the same server. Tried many of the techniques in this thread.

  • Hi,

    When you have a loop in a loop, the function like get_the_content() or get_field_object(‘autor’) dont know if they must use the ID of the first “looped” object or the second one …

    To solve it, get the id in variable and use it to clearly indicate which object is focused :

    
    if ( $wp_query->have_posts() ) : ?>
             <?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
                              // Set variables
                              $id = get_the_ID()
                              $title = get_the_title($id );
                              $description = get_the_content($id ); 
                              $field = get_field_object('autor', $id );
                              $colors = $field['value'];
                              $date = get_the_date( 'd.m.Y' );
                              // Output
                              ?>
                                <?php echo $colors;  ?>
                                <?php $wp_query->reset_postdata(); ?>
              <?php endwhile; ?>
       <?php endif; ?>

    Hope it helps.

  • Hey guys…

    I’m in the same boat here….bugger. Same exact error:

    Uncaught TypeError: Cannot read property ‘buttons’ of undefined
    at Object.buildQuicktags

    I have a plugin that (heavily) leans on ACF and also defines fields by PHP code. This issue is present in ACF Pro (5.7.5 & 5.7.6) but does not appear to be present in the “Free” version (5.7.2) when enabled for early access.

    I’m scratching my head here a bit and brainstorming on how to isolate what field might be causing the issue.

    Has anyone found a solution or have any clues to share?

    Thanks in advance.

  • Whoa – after more testing, I found the validation error only happens if I try to change the parent page. I can edit other fields on the page and it validates as I expect it to.

    I also found the same issue on another site on a WooCommerce product. The validation error happens on a required, but hidden and empty WYSIWYG field, and only when changing the Product Category. I can make changes to other fields and the product validates, even with the hidden, empty, required field.

  • Thanks, what if I wanted to do it with repeater rows? So…

    				<?php while ( have_rows('image_gallery') ) : the_row();  ?>					
    					<div class="col-md-6">
    						<div style="background-image: url(<?php the_sub_field('image'); ?>); background-size: cover; height: 240px;">
    							<a href="#" style="display: block; height: 240px;">							</a>
    						</div>	
    					</div>
    			    <?php endwhile; ?>
  • This is what I have so far:

    function displayprice() {
    
    	$return		= '';
    	$go_price 	= get_field( 'go_price' );
    	$go_link 	= get_field( 'go_link' );
            $bk_price 	= get_field( 'bk_price' );
    	$bk_link 	= get_field( 'bk_link' );
            $ml_price 	= get_field( 'ml_price' );
    	$ml_link 	= get_field( 'ml_link' );
    
    	if( $go_price && $go_link ) {
    		$return = '<a href="' . esc_url( $go_link ) . '">' . $go_price . '</a>';
    	}
    
            if( $bk_price && $bk_link ) {
    		$return = '<a href="' . esc_url( $bk_link ) . '">' . $bk_price . '</a>';
    	}
    
            if( $ml_price && $ml_link ) {
    		$return = '<a href="' . esc_url( $ml_link ) . '">' . $ml_price . '</a>';
    	}
    
    	return $return;
    	
    }
    add_shortcode( 'showprices', 'displayprice' );

    The issue I have is that if the first conditional is true, it doesn’t return any other. I need all 3 to return if data exists in each.

  • It would, just use the same method as the first with 4 conditionals

    $price1 = get_field( 'foo' );
    $link1 = get_field( 'bar' );
    if( $price1 && $link1 ) {
    	$return .= '<a href="' . esc_url( $link1 ) . '">' . $price1 . '</a>';
    }

    If none of the conditionals run, $return will be empty and you can check against that to return you default string.

  • If you’re variables are named like above you could loop through them with a for() loop and take advantage of the $i incrementor:

    function displayprice() {
    
    	$return		= '';
    	
    	for( $i = 1; $i <= 3; $i++ ) {
    		
    		$price = get_field( "price{$i}" );	// price1, price2, price3
    		$link  = get_field( "link{$i}" );	// link1, link2, link3
    		$return .= sprintf(
    			'<a href="%1$s" class="%2$s">%3$s</a>',
    			esc_url( $link ),
    			"price{$i}",
    			$price
    		);
    		
    	}
    	
    	if( empty( $return ) ) {
    		$return = __( 'Not Available' );
    	}
    
    	return $return;
    	
    }
    add_shortcode( 'showprices', 'displayprice' );
  • ACF only stores the ID of the field for the meta_key/meta_value. CF7 (or the add on your using) is directly accessing the meta value and not going through ACF to get the value.

    In order to do this you’ll need to create your own shortcode to add here
    [dynamichidden manual_url "CF7_get_post_var key='asp_manual_url'"]
    instead of using the [dynamichidden] add on. Or, alternately if this shortcode allows filtering so that you can filter the value used in order to get the file url from the ID. You’ll need to ask the authors of the dynamic text extension if the value can be filtered.

  • I found a possibly unstable solution but it seems to work so far without any kind of notices or errors ( as of yet ). It takes advantage of both the relationship query hook to set a specific flag and the posts_clauses hook to join the postmeta table and search on that. The SQL solution was found via Iconic WP blog post of a similar nature.

    /**
     * Product relationship field - include searching SKU
     * 
     * @param Array $args
     * @param Array $field
     * @param Integer $post_id
     * 
     * @return $args 
     */
    function prefix_product_relationship_query_mods( $args, $field, $post_id ) {
    
    	$args['post_status'] = 'publish';
    
    	if( ! empty( $args['s'] ) ) {
    		$args['acf_sku_search'] = true;
    	}
    
    	return $args;
    
    }
    add_filter( 'acf/fields/relationship/query/name=field_name', 'prefix_product_relationship_query_mods', 10, 3 );
    
    /**
     * Modify the query clauses to search on the postmeta table when asked to :)
     *
     * @param Array $clauses
     * @param WP_Query $query
     *
     * @return Array $clauses
     */
    function prefix_acf_relationship_search_sku( $clauses, $query ) {
    
    	global $wpdb;
    
    	if( $query->get( 'acf_sku_search', false ) ) {
    
    		$clauses['join'] 	= " LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ";
    		$clauses['where'] 	= preg_replace(
    			"/\(\s*{$wpdb->posts}.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
    			"({$wpdb->posts}.post_title LIKE $1) OR ({$wpdb->postmeta}.meta_key = '_sku' AND {$wpdb->postmeta}.meta_value LIKE $1)",
    			$clauses['where']
    		);
    		$query->set( 'acf_sku_search', false );	// Set to false just in case.
    
    	}
    
    	return $clauses;
    
    }
    add_filter( 'posts_clauses', 'prefix_acf_relationship_search_sku', 10, 2 );
  • You can’t search content OR a custom field by default in WP. You have to modify the query after WP has constructed it. See this explanation of how to do this https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

  • add a counter and break when the limit is reached, or use a for loop instead of a foreach loop.

    
    <?php 
      // using counter
      $images = get_field('gallery');
      if ($images) {
        $counter = 1;
        ?>
          <ul>
            <?php 
              foreach( $images as $image ) {
                ?>
                  <li>
                    <a href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                    </a>
                    <p><?php echo $image['caption']; ?></p>
                  </li>
                <?php 
                $counter++;
                if ($couner == 10) {
                  break;
                }
              }
            ?>
          </ul>
        <?php 
      }
    ?>
    
    
    <?php 
      // using for loop, this is the one I'd prefer
      $images = get_field('gallery');
      if ($images) {
        ?>
          <ul>
            <?php 
              for($i=0; $i<count($images) && $i<10; $i++) {
                $image = $images[$i];
                ?>
                  <li>
                    <a href="<?php echo $image['url']; ?>">
                         <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                    </a>
                    <p><?php echo $image['caption']; ?></p>
                  </li>
                <?php 
              }
            ?>
          </ul>
        <?php 
      }
    ?>
    
  • WP does not allow shortcodes as attributes of other shortcodes. https://codex.wordpress.org/Shortcode_API#Square_Brackets

  • So, the problem was that when a field is set with a visual editor, in WPML translation it was a default one-line field. If anyone has the same problem, you actually need to manually specify that the field should be “visual” in wpml-config.xml or in /wp-admin/admin.php?page=wpml-translation-management%2Fmenu%2Fsettings&sm=custom-xml-config

    Here’s my example for one field:

    
    <wpml-config>
        <custom-fields>
            <custom-field action="translate" style="visual">YOURFIELDNAME</custom-field>
        </custom-fields>
    </wpml-config>
    
  • I thought I should add more details.
    Here are my investigations :
    There is a screen capture of my post edition page attached.
    I found a json file in my theme that seems to deal with categories in an ACF-jon folder :

    
    {
        "key": "group_5ac5d1e87ab94",
        "title": "Categorie",
        "fields": [
            {
                "key": "field_5ad704be7333f",
                "label": "Afficher la catégorie courante",
                "name": "afficher_les_articles_dans_la_page_categorie",
                "type": "true_false",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "message": "",
                "default_value": 1,
                "ui": 1,
                "ui_on_text": "",
                "ui_off_text": ""
            }
        ],
        "location": [
            [
                {
                    "param": "taxonomy",
                    "operator": "==",
                    "value": "categorie"
                }
            ]
        ],
        "menu_order": 0,
        "position": "normal",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": "",
        "active": 1,
        "description": "",
        "modified": 1530175641
    }
    

    And finally that’s what I tried to add in function.php with no success :

    add_filter('body_class', 'add_acf_body_class');
     
    function add_acf_body_class($class) {
        $value = get_field('afficher_les_articles_dans_la_page_categorie', false, false);
        $class[] = $value; 
        return $class;
    }
  • Thanks very much for your help. Your explanation helped me to understand how hooks work.

    It’s actually on the archive page I want to add the ACF so in content-product.php using ‘woocommerce_after_shop_loop_item_title’ should have worked, but my theme (Astra) also seems to be influencing that area, so in the end I hid the title using the theme customiser and then in functions.php

    /**
     * ADD THE ACF DESCRIPTOR BY REMOVING THE FUNCTION AND REPLACING IT WITH OUR OWN - YOU MUST ALSO HIDE THE TITLE IN ASTRA CUSTOMISER
     */
    function sly_switch_loop_title(){
        remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
        add_action( 'woocommerce_after_shop_loop_item_title', 'sly_template_loop_product_title', 15 );
    }
    add_action( 'woocommerce_before_shop_loop_item', 'sly_switch_loop_title' );
    
    function sly_template_loop_product_title() {
        echo '<h4 class="sly-custom-shop-list-title">' . get_the_title() . '</h4>';
    	echo get_field( 'descriptor' );
    }
  • Thanks for your answer John, my question is if there is a video tutorial to integrate ACF in another plugin? since I do not understand the following tutorial well.

    https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

  • Shortcodes are meant to return data instead of echo it out. Additionally, it looks like the concatenation is malformed after $link1. Any time you’re combining variables with strings you need to use period . to connect them and only a semicolon at the very end. The variables are also not right – you use ‘price1’ in for the field parameter but $go_price is the variable. The anchor needs double quotes to surround the attribute URL. And the conditional needs 2 ampersands.

    All in all it should look something like this:

    function displayprice() {
    
    	$return		= '';
    	$go_price 	= get_field( 'price1' );
    	$go_link 	= get_field( 'link1' );
    
    	if( $go_price && $go_link ) {
    		$return = '<a href="' . esc_url( $go_link ) . '">' . $go_price . '</a>';
    	}
    
    	return $return;
    	
    }
    add_shortcode( 'showprices', 'displayprice' );
Viewing 25 results - 9,201 through 9,225 (of 21,339 total)