Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • You’re my hero 🙂 Thank you.

    Final code:

    add_action( 'pre_get_posts', 'book_custom_orderby' );
    function book_custom_orderby( $query ) {
      if ( ! is_admin() )
        return;
      if (empty($query->query_vars['post_type']) || $query->query_vars['post_type'] != 'book') {
      return;
      }
      if (empty($_GET['orderby'])) {
        $query->set( 'meta_key', 'order-no' );
        $query->set( 'orderby', 'meta_value_num' );
    	$query->set( 'order', 'ASC' );
      }
    }
  • Is it possible? Yes. Coding will be required.

    See this topic https://support.advancedcustomfields.com/forums/topic/category-taxonomy-in-repeater-not-saving/

    This is the most recent, but this is a common question.

  • You need to check that you are only applying it to the post type in question.

    
    if (empty($query->query_vars['post_type']) || $query->query_vars['post_type'] != 'your-post-type') {
      return;
    }
    
  • This reply has been marked as private.
  • I did my best using the code provide, it was a guess. I am just trying to show you how you would insert the field values into the data.

    The content inside of data-bs-chart="" is a JSON object. The JSON object can be constructed as a PHP array and then converted to a JSON object. This allows you to insert the values PHP array where they are needed.

  • I cannot tell what you need help with by looking at the code you provided, it seems incomplete. I assume you did not include everything because there would be a lot of code and I appreciate that, but it’s hard to tell from what was provided.

    The best that I can do is tell you what I do when I have to use a single component in multiple places.

    The first thing is that I try to use the same field group in all of these locations so that I can use all of the same field names. The problems is that with options pages that you need to have a way to separate the different options pages.

    When setting up an options page you can set the post_id that will be used for the fields on the options page. What is not well known is that you can set this to a text value. So for example

    Options page for 'vacancies_archive' the post ID for this options page could be set to 'vacancies_archive_options' and then the post ID for 'new_cars_archive' could be set to 'new_cars_archive_options'. What happens here is that the "option_name" value of these fields in the options page are prepended with this post ID value. ACF normally uses "options" so that fields in the options table have names that are constructed as "options_{$field_name}". By using a different value for the post ID you end up with "vacancies_archive_options{$field_name}" and "new_cars_archive_options{$field_name}"

    however, you should try to keep these post ID “names” short because there is a limit on the length of "opion_name" in the DB. I am only using these as examples. I would probably use something simple like "vacancy_options" or "new_car_options".

    Doing this makes it possible to use the same field names because
    if (have_rows('repeater_name', 'vacancy_options'))
    and
    if (have_rows('repeater_name', 'new_car_options'))
    refer to 2 completely different fields even if the repeater field name is the same.

    With that in place you simply need to figure out what “post ID” to use. For this I would create a function that looks at the queried object and then returns the correct ID.

    Then I would use a template part for the "hero_section". This template part would call the function that gets the ID and then loops over the correct repeater using that post ID.

  • This reply has been marked as private.
  • I’m focusing mainly on the issue of the autocomplete dropdowns not working when there are multiple instances of the form on the page right now.

    I was able to determine that it did work to have multiple instances with version 5.9.9, but it stopped working with 5.10(.0).

    I’m doing a diff between these versions and not surprisingly there are a ton of changes. It could be difficult to nail it down, and is probably not worth me investing the time in right now.

    I took a look at the changelog for 5.10 and I think this is the item that is most likely to be connected to whatever is causing the problem for me:

    Fix – Fixed issue where Select2 search input wouldn’t have focus in WordPress 5.8+

    I’m guessing that they fixed this focus issue by making a change to a jQuery selector — something that probably was not using a # (id selector) before, but should have been, now is, and I had previously been exploiting a bug without realizing it.

    Oh well…

  • 
    <?php 
      // create a php array that represents the JSON object
      $canvas_data = array(
        'options' => array(
          'maintainAspectRatio' => false,
          'legend' => array(
            'display' => false,
          ),
          'title' => array()
        ),
        'type' => 'donunt',
        'data' => array(
          'labels' => array(),  // this array will be populated from the repeater
          'datasets' => array(
            'label' => '',
            'backgroundColor' => array('#4e73df', '#1cc88a','#36b9cc'),
            'data' => array() // this array will be populated from the repeater
          )
        )
      );
      // loop over repeater and populate object
      if (have_rows('donut_graph_details')) {
        while (have_rows('donut_graph_details')) {
          the_row();
          $canvas_data['data']['labels'][] = get_sub_field('title');
          $canvas_data['data']['datasets']['data'][] = get_sub_field('percentage');
        }
      }
      // use json encode to output attribute
    ?>
    <canvas data-bs-chart="<?php echo json_encode($canvas_data); ?>"></canvas>
    
  • This reply has been marked as private.
  • That’s interesting, to pursue what might have changed recently. I’ve never used this on the front end without requiring login, so I haven’t had this extent of trouble, but it’s possible that a “lesser” version of the same issue is affecting my logged-in form display too.

  • I do not know what you are using or how it works. I need to see the code that you would add to your <canvas> element for the data points and how it would be added normally if you were going to hard code it so that I can help you populate that data from ACF.

    If that is in there and I’m missing it you will need to explain to me what part of that code is the data that you want to use and how it relates to the acf fields in question.

  • Thanks John, I was able to upgrade my code using an array eventually.

    function create_post_after_order( $order_id ) {
      if (  $order_id instanceof WC_Order ){
        return;
      }
    	
      $order = wc_get_order( $order_id );
      $order_items = $order->get_items(); 
    	
    	foreach ( $order_items as $item_id => $item_data ) {
        $product = $item_data->get_product();
    	$qty.= $item_data->get_quantity();
        $name.= $product->get_name();
      }
    	
    	$new_post = array(
        'post_title' => "Order {$order_id}",
        'post_content' => $content,
        'post_status' => 'private',
        'post_date' => date('Y-m-d H:i:s'),
        'post_author' => $user_ID,
        'post_type' => 'groeiproces',
        'post_status' => 'publish',
      );    
      $post_id = wp_insert_post($new_post);
    
    // repeater field with multiple subfields
    $class_field_key = 'field_61645b866cbd6';
    $class_subfield_name = 'field_61645b916cbd7';
    $class_subfield_colour = 'field_6165450699ffa';
    $class_names = array($name,$name);
    $class_colours = array($qty,$qty);
    
    foreach ($class_names as $index => $class_names) {
    	$class_value[] = array($class_subfield_name => $class_names, $class_subfield_colour => $class_colours[$index]);
    	update_field( $class_field_key, $class_value, $post_id );
    }
        
    }
    add_action( 'woocommerce_thankyou', 'create_post_after_order', 10, 1 );

    Right now the only problem is that this combines the values in one field. e.g.

    Name
    Product1Product2

    Quantity
    11

    Does anyone know how to split those values and save them separated. e.g.

    Product1 1
    Product2 1

    Thanks in advance!

  • This reply has been marked as private.
  • I’m using ACF repeater fields and there are two sub field. One is label and other field has data.

     <?php if( have_rows('donut_graph_details') ):  ?>
    				
                  <?php while( have_rows('donut_graph_details') ): the_row() ;   
                    
    			$title = get_sub_field('title');
    			$percentage = get_sub_field('percentage');
    			?>
    						
    	<canvas data-bs-chart=”{"type":"doughnut"
    													,"data":{"labels":["Direct","Social","Referral"]
    													,"datasets":[{"label":""
    
    													,"backgroundColor":["#4e73df","#1cc88a","#36b9cc"]
    													,"borderColor":["#ffffff","#ffffff","#ffffff"]
    													,"data":["50","30","15"]}]}
    
    													,"options":{"maintainAspectRatio":false,"legend":{"display":false}
    													,"title":{}}}”>
    													</canvas>
    <?php   endwhile; endif;?>
  • This is the closest I got to what I want, but it isn’t the proper way. I need to be able to enter any post per page. And, the current way depends on the artists. And BCS of it, post per page doesn’t work properly.

    <?php 
                    $relation = new WP_Query( array(
    		            'tax_query' => array( 
    							array(
    								'taxonomy' => 'continent',
    								'field'    => 'term_id',
    								'terms'    => 836,
    							)
    						), 
     						'post_type'         => 'artist',
    					'posts_per_page'	=>  -1 ,
    
    				) );
    
             
    				if( $relation->have_posts() ) : 
    
    				while ( $relation->have_posts() ) : $relation->the_post(); ?>	
    
    					<?php
    
    					$featured_posts = get_field('relation');
    
    					if( $featured_posts && is_array($featured_posts) ):
    					
    				
    					$new_featured_posts = get_posts( array(
    						  'post_type'        => 'event',
    			              'post__in' => $featured_posts,
    			              'posts_per_page' =>4,
    						  'order' => 'DESC',
    						  'orderby' => 'meta_value',
    						  'meta_key' => 'webinar_date',
    					) );
    					?>
     
    				    <ul>
    						<?php
    					    foreach($new_featured_posts as $post){
    					    	?>
    					    		<li>
    						             <?php the_title(); ?> 
    									<p>
    										<?php the_field( 'event_date' ); ?>
    									</p>
    						        </li>
    					    	<?php
    					    }
    			
    			         ?>
    				    </ul>				    
    					
    				    <?php 
    				    // Reset the global post object so that the rest of the page works correctly.
    				    wp_reset_postdata(); ?>
    
    				<?php endif; ?>
     
    			<?php endwhile;  ?>
     
    			<?php endif;  ?>
  • You can

    1) Use the link I provided above to do a reverse relationship query from the “country” post to the testimonial posts

    2) Code a bidirectional relationship

    3) Use a plugin that creates bidirectional relationships.

  • Mr?

    I remember a discussion like this, unfortunately, I don’t remember the specifics of it or what I was thinking at the time I might have suggested it…..

    …. Did some more looking and I did find it. It was over 4 years ago and it was on the WP support forum for my plugin. Still can’t remember WTH I was thinking. Recording where the relationship was created would be incredibly difficult to record and maintain. Not to mention that I’d need to create some type of a usable function to allow you to get incoming vs outgoing relationships.

    One of the things about my plugin is that it is build for an extremely simple use case that requires exactly zero additional coding for that use case. This is the only reason that it still exists.

    How I would do this if I had to do this.

    I would build 2 relationship fields. I would not use a plugin. One of these fields would be editable, the other would not be editable and I would remove this field from the post editor using an acf/prepare_field filter. Or I would somehow disable this field using JavaScript or hide it using CSS.

    I would then code a 2 way relationship between these 2 fields. When saving a post I would update the hidden field based on the editable field. This way the field that is editable always refers to the “To” or “Outgoing” relationships and the hidden field always refers to the “From” or “Incoming” relationships.

    If I wanted to show both the outgoing and incoming relationships I would try to figure out how to make the incoming field read only or in some why not editable. I don’t know if that is actually possible so as a last resort I would create a message field and using an acf/prepare_field filter I would dynamically populate the message with a list of the incoming relationships with links to edit those posts.

    In this way I would have both incoming and outgoing relationships available in different fields and could use them as needed.

  • The relationships are setup like this:

    – Related Fields Country, Continent
    — They are both ACF Post Objects, set to allow multiple, and to display on post types of Testimonial.

    So these are not set to show in blocks, but blocks are being used to display Testimonials as I am trying to and already in other custom blocks showing testimonials in some other way.

    I’m not sure if that answers your question, but i will also read about the link you sent of querying relationship fields.

  • I cannot help you with blocks.

    This issue is that the the relationship in the testimony post only stores post ID values of the country and continent posts. What you are trying to accomplish cannot be done using wp_query, or at least not a single query, unless you already know the ID values of the country continent post, if you are building this on a specific country or contentment page then this could be done because you have the correct post ID. However it cannot be done using blocks because the relationship field is not stored in post meta when using the new block editor, the fields are stored in “post_content”

    Sorry, I’m not sure if this is any help because I don’t know how these relationships are set up for the testimonial. Are they in blocks or not?

    This is how you would do this if you were using acf fields not in blocks.
    https://www.advancedcustomfields.com/resources/querying-relationship-fields/

  • So the issue was that this was being displayed in a vue app which, for some reason, caused the twitter widgets.js rendering to fail probably due to timing of sorts.

    I solved this by loading the script in my template according to https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/set-up-twitter-for-websites and triggering the widget load on $nextTick in the callback.

    
    window.twttr = (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0],
        t = window.twttr || {};
      if (d.getElementById(id)) return t;
      js = d.createElement(s);
      js.id = id;
      js.src = "https://platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js, fjs);
    
      t._e = [];
      t.ready = function(f) {
        t._e.push(f);
    
        this.nextTick(() => twttr.widgets.load())   
      };
    
      return t;
    }(document, "script", "twitter-wjs"));
    
  • Yeap, you’re right. This does the trick. Thanks!

    Just for future reference, here is my working code:

    add_action( 'pre_get_posts', 'book_custom_orderby' );
    function book_custom_orderby( $query ) {
      if ( ! is_admin() )
        return;
      if (empty($_GET['orderby'])) {
        $query->set( 'meta_key', 'order-no' );
        $query->set( 'orderby', 'meta_value_num' );
    	$query->set( 'order', 'ASC' );
      }
    }
  • I can’t process feature requests, you might want to contact the developers https://www.advancedcustomfields.com/contact/

Viewing 25 results - 5,151 through 5,175 (of 21,331 total)