Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi, ulascansadi. I ran into this problem and successfully got it solved today. Please check whether you used any function where ‘date’ is mentioned. In my case, one of my custom fields is called ‘date’ and then I wrote a function to make the column of this custom field sortable, which caused the problem.

    function cpt_date_orderby( $query ) {
     $orderby = $query->get( 'orderby' );
     if( 'date' == $orderby ) {
        $query->set('meta_key', 'date');
        $query->set('orderby', 'meta_value_num');
     }
    }
    add_action( 'pre_get_posts', 'cpt_date_orderby' );

    The problem lies in line 3, where ‘date’ is value for the parameter. I replaced ‘date’ with a different string, like ‘date1’, and that’s why I solved the problem.

    It seems ‘date’ is a reserved word in WordPress, and should be used carefully.

  • Ok, I have just realised that I am trying to obtain block data, rather than post data that does not exist. Silly me.

    My next question is, how do I get the block data, when it isn’t returning any via get_template.

    I am building a set of global templates for the blocks which is why I am including them, rather than having the code directly in the template.

  • Jhon, thanks for taking your time. Your suggestion shows how to rename a previously entered value and it works (maybe I’ll need it in the future). I think I made the mistake at the beginning of the project a few years ago by not providing the possibility of inserting multiple values ​​for that type of field: I started with a text type field and I continued with that by inserting values ​​separated by commas . I will continue to use it like this for this project. The conversion of the field type from text to select creates the inconvenience that I have exposed in the question and that I cannot solve by myself. Thanks again

  • Works perfect! One more question, if i have 3 custom fields. How i can display them separately?

    One hook for one field, Another for another.
    Can you help?

  • A true/false field saves a “1” for true and “0” for false.

    
    qrray(
                        'key'       => 'show_document',
                        'compare'   => '=',
                        'value'     => '1'
                    )
    
  • It is a date/time field Set to return/show in this format:

    2021-01-23 12:01:54 | Y-m-d H:i:s

    So my thinking goes, i need to first establish if an unpublished date have been set, and if it has compare it to the current time.

    This is where im at right now: still not working as intended:

       $unpublish      = get_field('unpublish');
        $current_time   = date( 'Y-m-d H:i:s' );
    
        if( ! empty($unpublish) ) {
            array_push( $metaQuery, array(
    
                'key'       => 'unpublish',
                'compare'   => '>',
                'value'     => $current_time,
                ),
            );
        }
    
  • I’ve got the sub fields in the first repeater posting fine. But, I can’t quite figure out how to get the nested repeater working properly.

    Here’s the code I have so far:

    $event_field_key = ‘field_535e6b9ffe3da’;

    $events[] = array(
    ‘start-date’ => $startDate,
    ‘end-date’ => $endDate,
    ‘notes’ => $_POST[‘p’.$p.’-notes’],
    ‘start-end-times’ => array(
    ‘start-time’ => ’09:00′, // would be dynamic
    ‘end-time’ => ’17:00′ // would be dynamic
    )
    );

    update_field($event_field_key, $events, $post_id);
    I’m not sure if I can just nest another array in there, or if I need to do something else.

  • Is it a date field or a date/time field

    ACF stores date fields in “Ymd” format in the DB so you need to use this format in your query.

  • @kuhada

    Hi,

    Gallery field has that bulk option dropdown that allows me to sort images in gallery field by title, reverse order etc…

    I don’t see this possibility when editing a Photo Gallery field when creating a custom post having such a field attached. Could you please elaborate a little?

    Thanks in advance.

    Patrick

  • Does not make any sense to me at all. I would say that there is some invisible character in there but that would make the results more odd than what you’re seeing.

    The only other thing I can think of is that there’s another filter being applied that you might be unaware of. I would try displaying all of the query after it’s run to see if there’s any arguments that should not be there.

    
    $the_query = new WP_Query(array(
    'post_type'		=> 'carsales',
    'posts_per_page'	=> -1,
    'meta_key'		=> 'car_make',
    'orderby'		=> 'meta_value',
    'order'			=> 'DESC'
    ));
    echo '<pre>'; print_r($the_query); echo '</pre>';
    
  • Thank you so much! That worked. I understand now I can add those query to the function. Thank you.

  • 
    $query->set('meta_value', date('Ymd'));
    $query->set('meta_compare', '>=');
    

    https://developer.wordpress.org/reference/classes/wp_query/

  • When you submit values through a form on a web page the browser may escape special characters like single quotes. It may also convert html entities. These changes may cause the two compared values to look the same but to actually be different strings when compared.

    However, looking back at your code I thing the reason for your problem is something else that I missed the last time. You need to supply the post ID when getting fields.

    
    if ($_POST['acf']['field_5fd213a8c6dfe'] != get_field('field_5fd213a8c6dfe', $post_id)){
    
  • Hello,

    Thanks for your answer, I think it will be ok.
    Just one question :
    How get I get the field_key from the field_name ?

    For example I do this :
    $current_status = get_field('status', $post_id);
    to retrieve the current value, beofre save.

    But to get the posted value I have to first get the key of this “status” field.

    Thanks
    Regards

  • For those interested in the feature, here’s how it worked for me.

    function.php

    
    // Loop Gallery Cat1
    
    function my_custom_gallery_cat1() {
        query_posts(array(
            'post_type' => 'gd_project',
            'orderby' => 'rand',
            'posts_per_page' => 10,
            'tax_query' => array(
                array (
                    'taxonomy' => 'gd_projectcategory',
                    'field' => 'slug',
                    'terms' => 'example-terms',
                )
            ),
        ));
        ?> <div class="masonry">
        <?php
        while (have_posts()) : the_post();
            $image_field = get_field('image');
            $image_url = $image_field['url'];
            $image_alt = $image_field['alt']; ?>
            <div class="grid-item">
            <a href="<?php echo get_permalink( $post->ID ); ?>" target="_blank">
            <img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>" />
            <h4><?php the_field( 'title' ); ?></h4>
            </a>
            </div>
        <?php endwhile; ?>
        </div> <?php
    }
    add_shortcode('example-terms', 'my_custom_gallery_cat1');
    

    single-example.php

    
    <div class="container-fluid">
    <div class="row">
    <?php echo do_shortcode('[categoria]');?>
    </div>    
    </div>
    
  • Hi John,

    i don’t quite understand your last post but i will try to figure it out. if i find a solution i’ll update here for other users.

    thanks for your help!

  • Best solution for me, copy repeater on a single text field and use it for query.

    More info: https://support.advancedcustomfields.com/forums/topic/copy-all-repeater-subfields-to-meta-key/

  • @hube2, thanks for your quick reply, I now see what’s going on. Two things:

    Firstly, the issue has obviously always been there, but only PHP 7.4 shows a notice.

    Secondly, maybe to help others:

    I have set up a field as yes/no toggle with ‘no’ as default value. Now when I create a new post and ‘no’ is already the right value for this field, then it won’t be created in the database on saving the post—as long as you don’t set it to ‘yes’, update the post, and set it back to ‘no’ again.

    So my solution here is to check if the field exists at all, and if not, assume it is ‘no’:

    
    $field_object = get_field_object( 'p_props_' . $grp . '_' . $v );
    
    if ( !$field_object ) :
      // Field doesn’t exist --> false
      // ...
    
    else :
      if ( $field_object['type'] == 'true_false' ) :
    

    Again, thank you very much!

  • I probably read your question when you first posted it but did not have an idea of a solution at the time. The recent spam comment caused your topic to move to the top of the list. I’ve just built a site, or I should say a few sites, where I have a “CTA” block that can be added to just about anything and I needed to find a way to do that.

  • What you are trying to do will only work on a term archive page.

    If index.php is showing the main archive, this is not a term archive and get_queried_object() is returning an object of “Post_Type”

    You would need to get the field from the category inside of your loop over the categories using $cat->term_id from your example code.

  • @nyrngrs24 I have done this with cloned fields, what I do is that I encapsulate the cloned field in group fields. Basically I create a group field and then I add one sub field which is the clone. This means that the fields are always sub fields.

    However, my purpose for doing this was so that I could add the same clone multiple times and the group field is named differently each time so it does require different have_rows() loops.

    I get around this by getting the entire group in my template and then calling a function with the array value returned.

    
    $args = get_field('group-field-name');
    my_function($args);
    
  • Hi there!

    Any news on this? Since running on PHP 7.4, I also encounter this error:

    Notice: Trying to access array offset on value of type bool in […]/products.php on line 169

    The code itself is quite simple:

    
    167|  $field_object = get_field_object( 'p_props_' . $grp . '_' . $v );
    168|
    169|  if ( $field_object['type'] == 'true_false' ) :
    

    And what does this error actually mean? I can’t see any issue on the page besides the debug error message.

    Thanks for any help!

  • I cannot be sure. $_POST['acf']['field_5fd213f4c6e02'] may be escaped in some way so that even if it’s the same that a simple string comparison may show them to be not equal.

  • here the full code maybe better to see what i have in mind.

    add_action('acf/save_post', 'save_customerdata', 5);
    
    function save_customerdata( $post_id ) {
        
    
      if( is_admin() ) {    
        return;   
      }
    
      if ( $_POST['acf']['field_5fd213a8c6dfe'] != get_field('field_5fd213a8c6dfe') ) {
      	$plz = $_POST['acf']['field_5fd213a8c6dfe'];
      }
    
      if ( $_POST['acf']['field_5fd213f4c6e02'] != get_field('field_5fd213f4c6e02') ) {
      	$street = $_POST['acf']['field_5fd213f4c6e02'];
      }
    
      if ( $_POST['acf']['field_5fd21405c6e03'] != get_field('field_5fd21405c6e03') ) {
      	$ptel = $_POST['acf']['field_5fd21405c6e03'];
      }
    
      if ( $_POST['acf']['field_5fd21410c6e04'] != get_field('field_5fd21410c6e04') ) {
      	$pfax = $_POST['acf']['field_5fd21410c6e04'];
      }
    
      if ( !empty( $plz ) OR !empty( $street ) OR !empty( $ptel ) OR !empty( $pfax ) ) {
        
    
        $post = get_post( $post_id ); 
        
    
        $user_id = str_replace("user_", "", $post_id);  
        
        $user_info = get_userdata($user_id);
        $first_name = $user_info->first_name;
        $last_name = $user_info->last_name;
        $user_email = $user_info->user_email;
        $user_login = $user_info->user_login;
        
        
        $to = '[email protected]';
        $headers = array('From: ' . $user_info->first_name. ' '.$user_info->last_name . ' <'.$user_info->user_email.'>');
        $subject = 'Profile Updated';
        $body = $user_info->first_name. ' '.$user_info->last_name. ' hat das Profil aktualisiert' . "\r\n";
        $body .= 'Benutzername: ' . $user_login . "\r\n";
    
        if ( !empty( $plz ) ) {
          $body .= 'PLZ / ORT wurde aktualisiert.' . "\r\n";
        }
        if ( !empty( $street ) ) {
          $body .= 'Strasse / Hausnummer wurde aktualisiert.' . "\r\n";
        }
        if ( !empty( $ptel ) ) {
          $body .= 'Telefonnummer wurde aktualisiert.' . "\r\n";
        }
        if ( !empty( $pfax ) ) {
          $body .= 'Faxnummer wurde aktualisiert.' . "\r\n";
        }
    
          
    
        wp_mail($to, $subject, $body, $headers );
    
      }
      
    }
  • I found the issue occurs in WP 5.5. In WP 5.6 everything works as expected.

    I replaced pro/assets/js/acf-pro-blocks.min.js with the 5.9.3 js-file and voila: the blocks were back.

    I guess it must have something to do with the jquery upgrade in 5.6…

Viewing 25 results - 6,001 through 6,025 (of 21,330 total)