Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • What are the names of your fields? What are the return values of your fields?

    This is just a general idea because I don’t have the details.

    
    <?php 
    // get all for fields and add them to an array
    $images = array();
    $images[] = get_field('image_field_1');
    $images[] = get_field('image_field_2');
    $images[] = get_field('image_field_3');
    $images[] = get_field('image_field_4');
    
    $current_image = 0;
    foreach ($images as $image) {
      $class = 'col-12';
      if (($current_image == 0 || $current_image == 2) && isset($images[$current_images+1])) {
        $class 'col-6';
      }
      ?><div class="<?php echo $class; ?>">image here</div><?php 
      $current_image++;
    }
    
  • money_format()

    On stackoverflow

    I’ll give the same note found on both of those links:

    The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

  • It seems there might be an issue in Elementor when querying products by category, specifically in selecting dynamic tags. To address this:

    Ensure all plugins, including Elementor and WooCommerce, are updated.
    Check Elementor Pro features, as advanced options may require the pro version.
    Refer to Elementor documentation and support forums for guidance.
    Consider creating a template for product archives using Elementor.
    Verify compatibility of dynamic content plugins with Elementor and WooCommerce.
    If the issue persists, contact Elementor support for assistance.
    Always perform backups before making changes.

  • Yes, the field names on the two post types would have to be the same to get the posts intermingled.

    In order to use 2 different field names the fields must have some relationship to each other.

    The only other options is would be to do two different queries, add the value of the acf field as a property of each post object, merge the results of both and then manually sort them in one of the php array sorting functions, likely with usort().

  • Hello John

    Many thanks for the advice. I have corrected the spelling mistake in is_search.

    The explanation regarding the sorting explains exactly what I see in the output of the search results after sorting by date.

    What I still don’t understand is that the sorting works when querying the two cpts on an overview page (first code section) but not in the search.

    Can I rewrite the search query so that sorting by date works or would ACF fields have to be named the same in order to enable sorting with $query->set('orderby', 'meta_value'); $query->set('meta_key', 'date_field_name');?

  • You have 2 problems

    The first is an error in your code, this

    
    $query->is_search
    

    should be this

    
    $query->is_search()
    

    The second thing is that ordering by several fields is not going to work the way I suspect you think it will or want it do. The second field will be order within the order or the first. An example:

    Let’s say that you have two fields

    1. State
    2. County

    and you order the posts first by state and then by county. It will order all of the posts alphabetically by state and then by county within each state.

    • State
      • county
      • county
      • county
      • county
      • county
      • county
    • State
      • county
      • county
      • county
      • county
      • county
      • county
  • Thank you for your quick solution, but unfortunately it doesn’t work. I tested it in various ways. In addition, there is no need for a new approach here, just an example of a mapping of multiple checkboxes from Gravity to ACF like in Franck’s code above, which works wonderfully.

    I have 9 multiple checkbox fields in Gravity that I want to map to 9 multiple checkbox fields in ACF. If anyone could help with this, that would be great! 😊

  • IT WORKS, THANKS FOR LISTENING 😀

    PS : I had 1st to query PLACE API
    and then query geocode API with place_id to get some value as street_name, country, etc…

  • May I answer my question..this solve my problem and it’s possible to achieved this through sql command query like the one below…I execute this 2 command on phpmyadmin

    or thru plugin used this – SQL Executioner, not updated for a long time but still working till now..I don’t have any problem with..

    UPDATE wp5m_usermeta AS m1
    JOIN wp5m_usermeta AS m2 ON m1.user_id = m2.user_id
    SET m1.meta_value = DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), m2.meta_value)), '%Y') + 0
    WHERE m1.meta_key = 'mag_age'
      AND m2.meta_key = 'mag_date_of_birth'

    or this one also works

    UPDATE wp5m_usermeta AS m1
    JOIN wp5m_usermeta AS m2 ON m1.user_id = m2.user_id
    SET m1.meta_value = TIMESTAMPDIFF(YEAR, m2.meta_value, CURRENT_DATE)
    WHERE m1.meta_key = 'mag_age'
      AND m2.meta_key = 'mag_date_of_birth'

    You can use STR_TO_DATE() to parse dates in other formats. STR_TO_DATE(m2.meta_value, ‘%Y%m%d’

    Thank you sir John Huebner

  • I think I know what could be causing the original issue now
    I said

    should be interpreting “d/m/Y” as “m/d/Y”

    So if you had a day like 30/01/2023 (30 Jan 2023) then strtotime() tries to use “30” as the month it is returning false (error) and that was likely the source of not sorting them correctly. Any date with a day > the number of days in what it is using for month would return an error.

  • Thank you very much @hube2. I was able to solve it by getting rid of strtotime() all together.. For reference here my code:

    
    <?php
    // Retrieve the list of posts from your CPT 'accreditations' with ACF fields 'description' and 'date'
    $posts = get_posts(array(
        'post_type' => 'accreditaties',
        'posts_per_page' => -1,
    ));
    
    // Create an associative array to group posts by year
    $groupedPosts = array();
    
    // Iterate through the list of posts and assign each post to the corresponding year
    foreach ($posts as $post) {
        $date = get_field('acc_aanvangsdatum', $post->ID);
        $parsedDate = DateTime::createFromFormat('d/m/Y', $date);
        $year = $parsedDate->format('Y');
    
        if (!isset($groupedPosts[$year])) {
            $groupedPosts[$year] = array();
        }
    
        $groupedPosts[$year][] = $post;
    }
    
    // Sort the grouped posts by year in descending order
    krsort($groupedPosts);
    
    // Iterate through the grouped posts and generate the HTML markup for each year's section
    foreach ($groupedPosts as $year => $posts) {
        echo '<button class="accordion"><h4>' . $year . '</h4></button>';
        echo '<div class="panel accreditaties">'; 
        ?>
    
        <div class="grid-container">
            <div class="grid-item" id="grid-item-title"><p>Aanvangsdatum</p></div>
            <div class="grid-item" id="grid-item-title"><p>Titel</p></div>
            <div class="grid-item" id="grid-item-title"><p>Status</p></div>
            <div class="grid-item" id="grid-item-title"><p align="right">Uren</p></div>
    
            <?php
            // Sort the posts within each year section by date in descending order
            usort($posts, function($a, $b) {
                $dateA = DateTime::createFromFormat('d/m/Y', get_field('acc_aanvangsdatum', $a->ID));
                $dateB = DateTime::createFromFormat('d/m/Y', get_field('acc_aanvangsdatum', $b->ID));
                return $dateB <=> $dateA;
            });
    
            foreach ($posts as $post) {
                $title = get_the_title($post->ID);
                $acc_aanvangsdatum = get_field('acc_aanvangsdatum', $post->ID);
                $acc_status = get_field('acc_status', $post->ID);
                $acc_uren = get_field('acc_uren', $post->ID);
                $acc_beschrijving = get_field('acc_beschrijving', $post->ID);
                ?>
    
                <div class="grid-item"><p><?php echo $acc_aanvangsdatum ?></p></div>
                <div class="grid-item"><p><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $title ?></a></p></div>
                <div class="grid-item status"><p><?php echo $acc_status ?></p></div>
                <div class="grid-item uren"><p align="right"><?php echo $acc_uren ?></p></div>
    
                <?php
            }
            echo '</div>'; // Close the grid-container
            echo '</div>'; // Close the panel for the current year
        }
        ?>
    
    <script>
      var years = document.getElementsByClassName("year");
      var i;
    
      for (i = 0; i < years.length; i++) {
        years[i].addEventListener("click", function() {
          var posts = this.nextElementSibling;
          if (posts.style.display === "block") {
            posts.style.display = "none";
          } else {
            posts.style.display = "block";
          }
        });
      }
    </script>
    <style>
    .grid-container {
      	display: grid;
      	grid-template-columns: 17% auto 16% 5%;
    	grid-column-gap: 0.5em;
    }
    .grid-item {
      border: 0px solid black;
      padding: 0em;
    }
    .grid-items-status-uren {
        display: contents;
    }
    </style>
    
  • UPDATE, @niq1982 code doesn’t work if you are using a get_field() where you actually specify the post_id (e.g. get_field(‘field_name’, $somePostID) ).

    I was able to fix this by checking if the $original_post_id is indeed a revision of the $post_id.

    function fix_acf_field_post_id_on_preview($post_id, $original_post_id)
    {
        // Don't do anything to options
        if (is_string($post_id) && str_contains($post_id, 'option')) {
            return $post_id;
        }
        // Don't do anything to blocks
        if (is_string($original_post_id) && str_contains($original_post_id, 'block')) {
            return $post_id;
        }
    
        // This should only affect on post meta fields
        if (is_preview()) {
    		if ( $original_post_id !== $post_id ) {
    			// Check if $post_id is a revision
    			$parent_post_id = wp_is_post_revision( $post_id );
    
    			if ( $parent_post_id === $original_post_id ) {
    				return get_the_ID();
    			}
    		}
        }
    
        return $post_id;
    }
    add_filter('acf/validate_post_id', __NAMESPACE__ . '\fix_acf_field_post_id_on_preview', 10, 2);
  • This should work, but I’m not 100% sure on that. I wrote it many years ago.

    https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/unique-repeater-checkbox

    It should affect all fields with the same field key on the page no matter where they are.

  • This must be done in php and cannot be done with an SQL query. ACF stores dates in “Ymd” format and not as a valid SQL date value. “Y-m-d H:i:s”.

    If you are doing this with a cron you will need to get all of the users, loop over them, get the fields and calculate in PHP and then update the field.

  • The solution with ACF relation field – post type ‘Products’ selected, and is set to ‘Post object’
    <ul class=”slider sp-interested-too-carousel product-carousel-boxes”>
    <?php
    $theProducts = get_field(‘sp_interested_too_products_choosing’);
    $theProductsIds = array();
    foreach ($theProducts as $product) {
    $theProductsIds[] = $product->ID;
    }
    $args = array(
    ‘post_type’ => ‘product’,
    ‘post__in’ => $theProductsIds,
    ‘posts_per_page’ => 10,
    ‘orderby’ => ‘rand’
    );
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
    while ( $loop->have_posts() ) : $loop->the_post();
    wc_get_template_part( ‘content’, ‘product’ );
    endwhile;
    } else {
    echo __( ‘No products found’ );
    }
    wp_reset_postdata();
    ?>

  • I confirm – it is still a thing.

    It happens for different field setups – I’m still doing a more through investigation of the issue.

    The problem that was reported to me recently was an editor using a simple flexible section (text field, textarea, button + repeater containing only one select input per row) – one day the data is there and the next day the whole section has a structure (so I see lets say 6 repeater rows) but all is empty, even fields marked as required.

    Using a DB backup I noticed that the sections order was changed between the days – so it could support this idea suggested initially by wplus.

    And no John Huebner – there is no conditional logic for this section.

    So far (in my investigation) I can see that the data for this section seems to be still in the DB but ACF does not see it to fill the forms with the values.

    I have:
    ACF Pro Version 6.2.3
    WordPress 6.4.1
    PHP Version 8.1.23
    max_input_vars 10000 (which is not exceeded by the edited page)
    + reasonable log max_execution_time & max_input_time

  • I’m having this problem on pages and it seems to happen seemingly randomly depending on who the last person was to change the draft post. Simply re-saving the draft sometimes fixes the problem.

    I did implement @niq1982 fix and that seems to solve the issue. Hopefully somebody fixes this soon because it makes it nearly impossible to draft post for review with any level of confidence.

    I am using WP 6.4.1/ ACF PRO 6.2.3.

  • Hi John, thanks for quick response!
    Ok I get it. So the best practice here would be to plan you sites URL structure ahead of adding content even if its only local dummy content that helps me see what Iam building.

    Is there a way to change/update those slugs by running search replace on the database itself?
    Thanks

  • I have steered you wrong.

    acf/fields/taxonomy/query is used for select fields and the select field does not use wp_list_categories()

    Select fields are rendered using ACF’s select field rendering, the only way to alter the title is with acf/fields/taxonomy/result, if that does not work then it is not possible.

  • I’m now facing exactly this same issue https://support.advancedcustomfields.com/forums/topic/add_filteracffieldstaxonomyquery-bug/#post-30884 filter is not getting called.

    I’m using WP 6.4.

  • Ok i have updated the code and now it works but somehow you need to have atleast one layout in flexible content for dragging to work.

    add_action('acf/input/admin_footer', function () {
        ?>
        <script type="text/javascript">
    
            (function($) {
    
                acf.add_action('ready', function($el){
                    $(".acf-flexible-content .values").sortable({
                        connectWith: ".acf-flexible-content .values",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                            $(this).find('.mce-tinymce').each(function() {
                                tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
                                tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
                            });
                        }
                    });
    
                    $(".acf-repeater .acf-flexible-content").sortable({
                        connectWith: ".acf-repeater .acf-flexible-content",
                        start: function(event, ui) {
                            acf.do_action('sortstart', ui.item, ui.placeholder);
                        },
                        stop: function(event, ui) {
                            acf.do_action('sortstop', ui.item, ui.placeholder);
                        }
                    });
                });
    
                acf.add_action('sortstop', function ($el) {
                    var $repeater = $($el).closest('.acf-input > .acf-repeater');
                    
                    if ($repeater.length) {
                        var $row = $el.closest('.acf-row');
                        var column_num = $row.attr('data-id');
    
                        // Loop through fields within the dropped element and update names
                        $el.find('[name^="acf[field_"]').each(function() {
                            var field_name = $(this).attr('name');
                            field_name = field_name.match(/\[([a-zA-Z0-9_-]+)\]/g);
                            field_name[1] = '[' + column_num + ']';
                            var new_name = 'acf' + field_name.join('');
                            $(this).attr('name', new_name);
                        });
    
                        // Loop through layouts within the flexible content field
                        $repeater.find('.acf-flexible-content .values > .layout').each(function(index) {
                            $(this).find('.acf-fc-layout-order:first').html(index + 1);
    
                            // Loop through fields within each layout and update names
                            $(this).find('[name^="acf[field_"]').each(function() {
                                var field_name = $(this).attr('name');
                                field_name = field_name.match(/\[([a-zA-Z0-9_-]+)\]/g);
                                var tempIndex = parseInt(field_name[3].match(/([0-9]+)/g));
                                field_name[3] = field_name[3].replace(tempIndex, index);
                                var new_name = 'acf' + field_name.join('');
                                $(this).attr('name', new_name);
                            });
    
                            // Trigger click on selected buttons to activate conditional logic
                            $(this).find('.acf-button-group label.selected').trigger('click');
                        });
                    }
                });
    
            })(jQuery);
    
            function GetSubstringIndex(str, substring, n) {
                var times = 0, index = null;
                while (times < n && index !== -1) {
                    index = str.indexOf(substring, index + 1);
                    times++;
                }
                return index;
            }
    
        </script>
        <?php
    });
    
  • @hube2 thanks for the reply and thanks for the details on how to provide feedback.

    What approach would you use to create a multi step form?

    I have effectively created tabs which have a next button so the user can scroll through the questions and then the next button changes to the submit button on the last tab. Obviously the validation is the trickiest part as ACF only does validation on submission of the form.

  • Not sure why you made your comment private.

    Like I said, I don’t know anything about building custom walkers and I don’t know why it would not be working.

    As far as my knowledge goes, when using a select field for taxonomy terms is that ACF calls wp_list_categories() and one of the filterable arguments for this function is ‘walker’.

    The best I can do is tell you how to see if your filter is being called. For this turn on WP Error Logging and then call the PHP function error_log() inside of your filter and see if your messages is logged. This is the only way to tell because it is a AJAX request. Your filter will only run when you click into the field and ACF tries to load more choices.

    If you want to possibly get input from someone other than me then you need to make your comment public, but it reality, your best choice for information on building a custom walker for WP is probably not this forum.

Viewing 25 results - 3,001 through 3,025 (of 21,345 total)