Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • @princeofabyss

    The plugin that you mention was created by a 3rd party and not the developers of ACF.

    However, I took a quick look. Going to be honest, I don’t know the answer, but my guess is that this is happening because load_plugin_textdomain() is being called too early in this plugin and this is causing the erratic behavior. I see that this plugin has not been updated in some time and this could also be part of the issue.

    https://developer.wordpress.org/reference/functions/load_plugin_textdomain/

    At any rate…

    If you look at the code for that pluing you’ll see a call to load_plugin_textdomain() inside of the plugin’s __construct() method. I would try moving this call into the plugin’s include_field_types() method as can be see in the field type starter code that the ACF developer provides here https://github.com/AdvancedCustomFields/acf-field-type-template/blob/master/acf-FIELD-NAME/acf-FIELD-NAME.php.

    Don’t know if this will fix your issue or not.

  • Hi All,

    I could do with some help on the inserter help panel.

    I have the following code:

    
    	// register a one column block
    	acf_register_block_type(
    		array(
    		'name'				=> 'one-column',
    		'title'				=> __('One Column'),
    		'description'		=> __('A one column block.'),
    		'render_template' 	=> get_template_directory() . '/blocks/content-one-column.php',
    		'icon'				=> 'menu',
    		#'icon'				=> file_get_contents( get_template_directory() . '/images/blocks/one-column.svg' ),
    		#'mode'              => 'auto', #Available settings are auto, preview and edit. 
    		'supports' 			=> array( 'align' => false ),
    		'keywords'			=> array( 'one column', 'layout' ),
    		
    		#'render_template'   => get_template_directory() . '/blocks/content-one-column.php',
    		#'enqueue_script'    => get_template_directory_uri() . '/blocks/content-one-column.js',
    
    		'example'  			=> array(
    									'mode' => 'preview',
    									'attributes' => array(
    										'data' => array(
    											#'title'		=> "One Column Block",
    											'content'	=> "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent euismod sem eget tortor suscipit, et ultricies lectus ultrices.",
    											#'content'	=> '<img src="'.get_template_directory_uri() . '/images/block-preview/one-column.jpg'.'">'
    											#'gutenberg_preview' => __('<img src="'.get_template_directory_uri() . '/images/block-preview/one-column.jpg'.'">'),
    										)
    									)
    								)				
    		)
    		
    	);
    

    My template (blocks/content-one-column.php) includes the fields:
    – title
    – content
    So my understanding is you use those in the ‘data’ field and when you hover over the block you want to add, it would then show this content.

    I replaced this with an image (thought it would be easier to style). Oddly, this was working but has now stopped. I can’t even get the previous one to work.

    Am I right in thinking you just need the above? You don’t need to enqueue_script a js file?

    Be great to get this working, so any pointers are very much appreciated!

    Thanks

  • @hube2 , John, sorry for hi-jacking the thread with this off-topic, I’m totally clueless about the issue below, and for a fact I know that if anyone is to help me figure it out, most probably that one will be you.

    So I noticed that 3-4 out of 10 times I make some edits in a post (any post) that has an ACF multi-date picker, after the post is re-published, the date picker calendar will lose its localization, until I interact somehow with it. Once I change the month, select an unselected date, or unselect a selected one, the calendar magically gets localized again. And because in my localization settings, Monday is starting the week, even that small detail gets changed as well… And ALL that is not happening every time… As I said, somehow it’s happening 3-4 times out of 10 maybe…

    In the video below, until @1:30 I published the post 3-4 times and the calendar didn’t lose its localization. Then suddenly, on @1:30, it lost it two times in a row (where you can see all things I described above). Then, at the end of the video, again it didn’t lose it after one more re-Publish…

    Any idea why this may be happening? It’s not super serious, as it’s happening in the backend, but still, I’d like to figure out why!

    https://www.youtube.com/watch?v=yKodqaCkrsg

  • This depends on what you’re looking for exactly.
    Do you have a range of dates that the start and end date of the event needs to be between? Do you have a date and anything after that date is shown? These would be completely different queries.
    For example, if I wanted all of the events with start or end dates after today, then I wouldn’t check the start date at all because if the end date is after today then the start date does not matter

    
    'meta_query' => array(
      array(
        'key' => 'end_date',
        'compare' => '>=',
        'value' => $today,
      )
    )
    

    But if I want events that are happening between two dates

    
    'meta_query' => array(
      'relation' => 'OR',
      array(
        array(
          'relation' => 'AND',
          array(
            'key' => 'start_date',
            'compare' => '>=',
            'value' => $start_range
          ),
          array(
            'key' => 'start_date',
            'compare' => '<=',
            'value' => $end_range
          )
        )
      ),
      array(
        array(
          'relation' => 'AND',
          array(
            'key' => 'end_date',
            'compare' => '>=',
            'value' => $start_range
          ),
          array(
            'key' => 'end_date',
            'compare' => '<=',
            'value' => $end_range
          )
        )
      )
    )
    
  • This worked for me to get the taxonomy terms for the current post with an ACF icon field attached:

    <?php $terms = get_the_terms( get_the_ID(), 'project_services' );
    $cat_icon = get_field('icon', $queried_object); 
    ?>
    
    <?php if( $terms ): ?>
    <ul class="menu">
    	<?php foreach( $terms as $term ): ?>
    	<li>
    		<a href="<?php echo get_term_link( $term ); ?>">
    			<?php $icon = get_field('icon', $term->taxonomy . '_' . $term->term_id);?>
    			<img src="<?php echo $icon ?>">
    			<?php echo $term->name; ?>
    		</a>
    	</li>
    	<?php endforeach; ?>
    </ul>
    <?php endif; ?>
    
  • The answer above was so close; the key to my success was $cart_item:

    function price_count_cart( $price_cart, $cart_item, $cart_item_key ) {
    	$product_id = $cart_item['product_id'];
    	$count_cart = get_field('count', $product_id);
    	if (!$count_cart) {
    		return $price_cart;
    	}
    	else {
    		return '<span class="custom-prc">'.$price_cart.' / <small>'.$count_cart.'</small></span>';	
    	}	
    }
    add_filter( 'woocommerce_cart_item_price', 'price_count_cart', 10, 3 );
  • This is what I’ve done so far. What this does is it adds the class .current to the selected checkbox and hide the rest. The problem I have now is that when you uncheck the box, the class .current is still there and when you check on another checkbox, it doesn’t work at all.

    $(document).on("click", "#three_img_plus_feature_img input", function () {
        $("#three_img_plus_feature_img").removeClass('current');
        $(this).closest("#three_img_plus_feature_img").addClass('current');
    
        if ($(this).is(":checked")) {
            $("#three_img_plus_feature_img:not(.current) label").css("display", "none");
        } else {
            $("#three_img_plus_feature_img:not(.current) label").css("display", "block");
        }
    });
  • Yup you’re quite right. I found this just before I saw your reply. I called esc_html simply because I was trying everything I could think of. : )

    As always, thank you John!

  • Got it working with this. Hope it helps someone.

    <?php if ( have_rows( 'profile') ) : ?>
              <div class="container px-5 mx-auto flex flex-wrap">
                <div class="flex flex-wrap -m-4">
    	       <?php while ( have_rows( 'profile' )) : the_row(); ?>
               <?php $profile_link = get_sub_field( 'profile_link' );?>
                <?php if ( $profile_link ) :
                  $permalink = get_permalink( $profile_link->ID );
                  $title = get_the_title( $profile_link->ID );
                  $creds = get_field( 'creds', $profile_link->ID );
                  $headshot_id = get_field( 'headshot', $profile_link->ID ); // Profile headshot media id
                  ?>
                    <div class="row w-48 mr-8" >
                    <?php echo wp_get_attachment_image( $headshot_id, 'thumbnail', '', ["class" => "twn-profile-pic mx-auto"] );?>
                    <p class='text-sm is-all-caps text-center mt-4'><?php echo $title; ?></p>
                      </div>
                      <?php wp_reset_postdata(); ?>
                      <?php endif; ?>
    	       <?php endwhile; ?>
             </div>
             </div>
                <?php else : ?>
    	                <?php // no rows found ?>
              <?php endif; ?>
  • I have finally found a working solution:

    <?php
    $file = get_field('dokumente_datei');
    $url = $file['url'];
    $image_id = $file['id'];
    $image_url = wp_get_attachment_image($image_id,'medium');
    if( $file ): 
    
    ?>
        <a href="<?php echo $file['url']; ?>">
           <?php echo ($image_url); ?></a>
    
    <?php endif; ?>
    
  • How pass multiple parameters in Ajax call jQuery in MVC?

  • You have it exactly. Our clients want to be able to add and move around various elements but they want each of the same type of element to work and look exactly the same every time they are used and they don’t want their employees putzing with design elements and they also don’t want to put many hours into training them on their company’s design guidelines.

    The issue with dealing with React is that it is a completely different development process that increases dev time, especially when you have a team of one. When you’re in a business where you need to deliver a web site at an affordable price, and withing a short timeframe, increasing the development time increases cost to the client and increasing cost to the client means that you do not sell custom web development.

    Many developers, from what I’ve seen and read, are either doing what I’m doing, using some other page building plugin/application for WP, or they are just leaving and many that can do so are going to ClassicPress. I would do the same but the company I work with also depends on several plugins that will not work in ClassicPress and there isn’t any plans to make them work, so I’d have to build anything that I need, once again increasing cost that we need to find a way to pass on to the client. Yes, there are some people using blocks and they are using ACF to help them achieve this because Elliot has taken part of the pain out of the equation by adding blocks capabilities to ACF. My biggest issue with doing this is the fact that my clients are businesses that usually need advanced sorting and filtering capabilities and blocks store all of their content in the “post_content” row of the post, making sorting and filtering based on these fields nearly impossible without jumping through a lot more hoops.

    The thought of WP dropping the classic editor is why I don’t use it. WP includes a classic block, this means that as long as this exists TinyMCE will be a part of WP. As long as TinyMCE is part of WP there will always be a WYSIWYG editor in ACF.

    As far as the viability of the flex field. The biggest reason that ACF Pro is popular is because of the repeater. A Flex field is actually a fancy repeater that allows different sub field for each row. While a Group field is actually a cut down version of a repeater that always has exactly one row. If you take the repeater out of ACF then there’s really no Pro. The death of the repeater would likely mean the death of ACF.

  • Adding a custom location rule seems to have changed quite a bit since I’ve set up custom location rules… luckily my legacy code seems to still be working on sites where it’s used.

    But because of the way that ACF works is seems like if it’s using the location rules that it should be checking all location rules, including custom rules. I say this because ACF’s rules are run on the same hooks as those that would run custom rules. The only reason I can see it wouldn’t is if there’s some reason the your rules have not been loaded prior to calling acf_get_field_groups().

    This could possibly happen if you try to get field groups before acf/init is run which will force a premature initialization of ACF that can have unexpected results.

  • This is an OLD question, but I stumbled upon it when trying to answer how to add items to the pre-defined Basic menu. Here is the code I’ve used, which was written using the information found at ACF.

    /********************************
    ADD ADDITIONAL TOOLBAR SET TO ACF WYSIWYG
    ********************************/
    if ( function_exists( 'get_field' ) ) {
      add_filter( 'acf/fields/wysiwyg/toolbars' , 'qd_toolbars'  );
      function qd_toolbars( $toolbars )
      {
        //INJECT/ADD AN OPTION INTO THE BASIC TOOLBAR
        $toolbars['Basic' ][1] = array_merge( array_slice( $toolbars['Basic' ][1], 0, 3, true ), array( 'subscript','superscript' ), array_slice( $toolbars['Basic' ][1], 3, null, true ) );
    
        //FIND MORE INFO ABOUT THIS OPERATION AT http://www.advancedcustomfields.com/resources/customize-the-wysiwyg-toolbars/
        // Add a new toolbar called "Very Simple"
        // - this toolbar has only 1 row of buttons
        $toolbars['Very Simple' ] = array();
        $toolbars['Very Simple' ][1] = array('bold' , 'italic' , 'underline', 'link', 'unlink' );
    
        // return $toolbars - IMPORTANT!
        return $toolbars;
      }
    }
  • @paulsvang

    I found the solution here : https://stackoverflow.com/questions/56553090/populate-acf-fields-using-wordpress-rest-api-js

    Just replace acf by fields like this :

    "fields": 
        {      
            "field_1" : "Titre",  
            "field_2" : 100
        }
  • I am not the developer, I just work here on the forums answering questions, but I do know a lot about ACF.

    There are a lot, and I mean A LOT, of developers like me that will avoid moving to gutenbug. The reason for this is that my clients do not want be able to edit how content looks on the site. All of my clients are larger companies where every page must look like every other page, every paragraph must look like every other paragraph. If they add an image gallery then every gallery must look and work identically. Most of the time those that are adding the content are not the site owners but people that my clients hire to do the content adding and they do not want or need these people to have any ability to alter the look and feel of anything. I also do not use classic editor even for simple page content. My feeling here is that ACF will always include a WYSIWYG field and this it what my clients want to use. All of my clients are used to using Word Processors and this is how they want to edit pages.

    I do not foresee either the flex field or the WYSIWYG field going anywhere any time in the near future.

    But like I said, I’m not the developer, just the guy that works this forum. To get an answer from the developer you’d need to contact him, he does not spend a lot of time on this forum, that’s why I’m here so that he can concentrate on fixing and improving ACF. You can try contacting him here https://www.advancedcustomfields.com/contact/

  • Use an acf/save_post filter, get the values of the repeater/sub fields (unfomatted) and save them as a standard WP meta field

    
    add_action('acf/save_post', 'gmf_to_standard_wp', 20);
    function gmf_to_standard_wp($post_id) {
      // make sure a user is being saved
      if (substr($post_id, 0, 5) != 'user_')) {
        return;
      }
      // get the user id
      $user_id = intval(substr($post_id, 5);
      // delete existing post meta so that we start fresh
      delete_user_meta($user_id, 'user_lon');
      delete_user_meta($user_id, 'user_lat');
      // loop over rows and save values
      if (have_rows('your-repeater', $post_id)) {
        while (have_rows('your-repeater', $post_id)) {
          the_row();
          // get value unformatted
          $data = get_sub_field('your-google-map-field', false);
          // you will need to excuse me here because I
          // don't know how this array is saved by ACF
          // or what the indexes are, so you will need to figure
          // this out. I am only guessing at "lon" and "lat"
          // add each value allowing multiple values
          add_user_meta($user_id, 'user_lat', $data['lat'], false);
          add_user_meta($user_id, 'user_lon', $data['lon'], false);
        }
      }
    }
    
  • Ok, I’ve been able to a bit further and can edit the widgets now.

    I’ve created an IF statement so that if the colour hasn’t been selected it will not show.

    However, they’re all coming back “no” despite 2 colours having selected.

    function woo_colour_swatches( $term_html, $term, $link, $count ) {
        
        $color = get_field('colour', $term);
    
        if( $colour ){
            echo 'Yes';
        }else{
            echo 'No';
        }
    
        echo '<a href=" '. $link .' ">'. $term->name .'</a>';
    
        return $some_modified_value;
    }
    add_filter( 'woocommerce_layered_nav_term_html', 'woo_colour_swatches', 10, 4 );

    **UPDATE**

    Mis-spelt color with colour

  • I think I’ve answered my own question. This seems to do the job for me:
    <?php if ( $rows[0] ) : ?>classNameHere<?php endif; ?>

  • I’ve got this answer from the ACF-Support.

    Thank you for your email.

    I hate to be the bearer of bad news but the acf_register_block_type() function currently does not support the ‘anchor’ property. You can have a look at its documentation here https://www.advancedcustomfields.com/resources/acf_register_block_type/.

    I hope this helps and kindly let me know how this goes :).

  • @hube2 thanks a ton for your reply. Truth is I solved this earlier today, slightly differently than your proposed solution, but still it’s solved. I’ll post the code that I used, and I’ll elaborate on it later.

    add_filter('acf/fields/post_object/result/name=screening_cinema', 'add_parent_to_cinema_options', 10, 4);
    function add_parent_to_cinema_options($text, $post, $field, $post_id)
    {
        if ($post->post_parent) {
            $text .= ' | ' . __('Parent', 'acf') . ': ' . get_the_title($post->post_parent);
        }
    
        return $text;
    }
    
    add_action('acf/input/admin_footer', 'add_js_for_disabling_cinema_options');
    function add_js_for_disabling_cinema_options() {
        ?>
        <script type = "text/javascript">
        (function($) {
            acf.add_filter('select2_ajax_results', function(json, params, instance) {
                if (instance.data.field.data.name === 'screening_cinema') {
                    json.results.forEach(function(element) {
                        if (typeof element.description === "undefined") {
                            element.disabled = "true";
                        }
                    });
                }
    
                return json;
            });
        })(jQuery);
        </script>
        <?php
    }

    First of all, I noticed in includes/fields/class-acf-field-post_object.php at lines ~259-275 the following piece of code:

    		// vars
    		$result = array(
    			'id'	=> $id,
    			'text'	=> $text
    		);
    		
    		
    		// look for parent
    		$search = '| ' . __('Parent', 'acf') . ':';
    		$pos = strpos($text, $search);
    		
    		if( $pos !== false ) {
    			
    			$result['description'] = substr($text, $pos+2);
    			$result['text'] = substr($text, 0, $pos);
    			
    		}

    According to this, it’s possible to add a description and a text param in the json object used in acf.add_filter(‘select2_ajax_results’, function(json, params, instance)

    That’s why I used the filter add_filter(‘acf/fields/post_object/result/name=screening_cinema’) to first add the parent part in the text shown, and then in the JS function I searched for the existence of the description param to decide whether I’ll disable the option or not.

    Different approach than yours, the same effect and maybe a bit faster, as I’m not creating that whole bunch of top-category IDs. Plus, I liked that for the selected option, I get this | Parent: <parent title> in the dropdown so that I know exactly what parent the selection belongs to.

    screenshot

    PS: The website is localized to my language that’s why you see that ” | Γονέας:” term in place of the ” | Parent:”.

    Anyway, thanks a million for your help! Regards.

  • I have got this somehow to work:

    <?php
    $text = get_field('dokumente_datei');
    $stripped_text = str_replace(".pdf","-pdf.jpg","$text");
    ?>
    
    <img src=<?php echo $stripped_text; ?>" width="100%">

    But it returns the full-size image and I need a smaller one for the post loop. As the smaller ones are named differently (pixel size added to the image names), it does not work either as I try to get it to work….

  • Thanks again for your help. I am pretty new with all this.

    I have now tried around several attempts, but I still get an error:
    Parse error: syntax error, unexpected ‘false’ (T_STRING), expecting ‘)’ in (…)/wp-content/plugins/oxygen/component-framework/components/classes/code-block.class.php(115) : eval()’d code on line 2

    <?php if( get_field('dokumente_datei') ): 
    $file_id = intval(get_field('dokumente_datei', false false));
    $image = get_attachment_image_src($file_id, 'thumbnail');
    
    ?>
    <img src="<?php echo esc_attr($image); ?>" />
    
    <?php endif; ?>

    Your help is highly appreciated!

  • 
    <div id="adobe-dc-view" style="height: 800px; width: 800px;"></div>
    <script src="https://documentcloud.adobe.com/view-sdk/main.js"></script>
    <script type="text/javascript">
    	document.addEventListener("adobe_dc_view_sdk.ready", function(){ 
    		var adobeDCView = new AdobeDC.View({clientId: "<CLIENT ID>", divId: "adobe-dc-view"});
    		adobeDCView.previewFile({
    			content:{location: {url: "<?php the_field('dokumente_datei'); ?>"}},
    			metaData:{fileName: "<?php the_title(); ?>"}
    		}, {embedMode: "SIZED_CONTAINER"});
    	});
    </script>
    
  • @laju is likely correct. The value that your getting (a string value of what appears to be an ID) indicates that you’re using some type of relationship field and your pre_get_posts filter is interfering with the query that ACF is doing. The following should be added to all pre_get_posts filters that are designed to filter the main query.

    
    if (is_admin())  || !$query->is_main_query()) {
      return;
    }
    
Viewing 25 results - 5,951 through 5,975 (of 21,330 total)