Support

Account

Forum Replies Created

  • So @drew321, I try again maha…

    For your question about post_id, you have multiple ways. Just, all depend of your structure. How you have set that? …

    Since I don’t know the answer, I’ll tell you again how I would do it hehe.

    With WordPress you can create admin pages, but with ACF Pro, you can do it in a simpler way.

    Put a look here: https://www.advancedcustomfields.com/resources/options-page/.

    If you manage your admin pages with ACF Options Pages, you’ll be able to user update_field with “option” value for your $post_id instead of a specific post ID.

    For your question about Fetch: Fetch has coming with modern browser. But Fetch is like Ajax and it’s JavaScript. Not related with WordPress. Put a look here: https://www.w3schools.com/js/js_ajax_intro.asp

    But with WordPress, you can manage Ajax/fetch with security. You need to use the hook wp_ajax_{action} or wp_ajax_nopriv_{action} for that. Put a look here: https://developer.wordpress.org/reference/hooks/wp_ajax_action/

  • @drew321 Probably, you want use “option” for the $post_id but I can’t be specific without more details. Maybe I’m wrong.

    For your question about fetch: fetch is like Ajax and it’s appear with modern browsers. Its JavaScript, not WordPress or PHP. You can put a look on this page for quick details: https://www.w3schools.com/js/js_ajax_intro.asp (scroll to bottom of the page for fetch info instead of Ajax)

    But with WordPress, you can manage Ajax/Fetch with security. With the wp_ajax_{action} hook. Put a look here: https://developer.wordpress.org/reference/hooks/wp_ajax_action/

  • Nice!


    @johnshuffles-com-au
    , forget my message. The John solution is the best.

  • To know if the difficulty of transferring to an options page is complicated, I would have to know your project.

    I also thought of another idea. You may also be able to integrate an ACF form into your WordPress admin page with “acf_form()”. Put a look here: https://www.advancedcustomfields.com/resources/acf_form/

    (But it’s just one idea among others.)

    Just know, you have several possibilities, but I can’t know if what I’m saying is well thought out because I don’t know your project.

  • With my last message, I forgot to tell you what you could do when it’s not an options page. For example, you save a publication in a CPT and you don’t have the ID before publishing.

    Use the “save_post” hook for this: https://www.advancedcustomfields.com/resources/acf-save_post/

  • Hi @johnshuffles-com-au !

    It’s only an idea: you can use Select field for that: https://www.advancedcustomfields.com/resources/select/

    After creating your field, transfert it to PHP with the ACF tool just there (yoursite.com/wp-admin/edit.php?post_type=acf-field-group&page=acf-tools), you’ll be able to use the “new WP_Query” for get your publications by author and fill up the select box.

  • Here is an example for people who want to understand:

    
    add_filter('acf/validate_value/key=field_65067bde5086e', 'checkEmails', 10, 4);
    add_filter('acf/validate_value/key=field_65067e4f26db1', 'checkEmails', 10, 4);
    
    function checkEmails($valid, $value, $field, $input_name){
    
        if(!isset($_POST['acf']['field_65067bd15086d'])) return $valid;
    
        $email = $_POST['acf']['field_65067bd15086d']['field_65067bde5086e'];
        $confirmEmail = $_POST['acf']['field_65067bd15086d']['field_65067e4f26db1'];
    
        if(
            !filter_var($email, FILTER_VALIDATE_EMAIL)
    
            ||
    
            $email !== $confirmEmail
        ){
    
            return 'test';
        }
    
        return $valid;
    }
    
  • Thanks @hube2!

    I haven’t tested it yet, but I’ll let you know!

  • So @drew321, I try again maha…

    (In fact, it’s my third test. I think the URL I share break my send, but I have no notice…)

    For your question about post_id, you have multiple ways. Just, all depend of your structure. How you have set that? …

    Since I don’t know the answer, I’ll tell you again how I would do it hehe.

    With WordPress you can create admin pages, but with ACF Pro, you can do it in a simpler way.

    Put a look here: advancedcustomfields[dot]com/resources/options-page/.

    If you manage your admin pages with ACF Options Pages, you’ll be able to use update_field with “option” value for your $post_id instead of a specific post ID.

    For your question about Fetch: Fetch has coming with modern browsers. But Fetch is like Ajax and it’s JavaScript. Not related with WordPress. Put a look here: w3schools[dot]com/js/js_ajax_intro.asp

    But with WordPress, you can manage Ajax/fetch with security. You need to use the hook wp_ajax_{action} or wp_ajax_nopriv_{action} for that. Put a look here: developer.wordpress[dot]org/reference/hooks/wp_ajax_action/

  • @hube2 I don’t know why, my answer don’t display. Do you see it? ….

    For real please, put a look on the forum. The hell I post and I can’t see my post or the forum said I’m a bot if I back and foward forum and Google for some search.

  • Thanks @hube2


    @drew321
    On my example, I write let canClick = false; But need to be true.

  • I think you can simply add style=”width: 50%;” in each td element or from your CSS.

    I said “I think” because HTML tables are far behind me and I could be wrong. (I prefer to recreate a table appearance with grid or flex ^^)

  • Hello John ( @hube2 )! A really big thank you!

    Does this method just allow me to check one field at a time or can I verify that my “email” field and my “email confirmation” field are the same at the same time?

    (sorry for my bad english)

  • Hey @hube2!

    Do you have correct the probleme? If yes, are you able to see my second post before this big tutorial? It’s an other big tutorial, but better hehe.

    If yes, could you replace it and remove my messages? Thanks!

  • Oh, sorry if I was not answer completely. I just understand now. (I need more practice in english hehe)

    Ok, you can play with your PHP like that, but know, you have in fact, multiple ways:

    (I supose you have your date in the format you give me. Let’s me know if it’s a timestamp.)

    
    <?php
    
        if(have_rows("gesloten", "option")){
            
            echo '<table style="width: 100%;">';
            
                echo '<tbody>';
            
                while(have_rows("gesloten", "option")) : the_row();
    
                    $birthDayName = get_sub_field("feestdag");
    
                    $startDate = get_sub_field("datum");
                    $endDate = !empty(get_sub_field("eind-datum")) ? ' - ' . get_sub_field("eind-datum") : null;
                    
                    $startToEndDate = $startDate . $endDate;
    
                    echo '<tr>';
                        echo '<td>'. $birthDayName .'</td>';
                        echo '<td>'. $startToEndDate .'</td>';
                    echo '</tr>';
    
                endwhile;
            
                echo '</tbody>';
            
            echo '</table>';
        }
    
    ?>
    
  • And now, I just update my second post and he deleted himself.

    Hahaha. Hey lol, just no.

    I’ll help you when ACF’ll correct there Forum. The hell.

  • Ok,

    (btw ACF, I have takes 45 minutes-1 hour for writing my shit. I’m crying.)

    So, I started by telling you that it was going to be a little hard for me to help you without knowing the structure of your field group.

    For this reason, but also seeing that there is a lack of knowledge on your part, I preferred to show you how I would do it from A to Z.

    Oh! I started by telling you a big sorry for my bad english too hehe.

    So it start like this:

    First of all, create your HTML structure without your PHP:

    (I purposely used a different structure than yours to show other possible ways)

    
    <form id="mySuperForm" action=""  method="POST">
        
        <input type="text" name="key" id="key">
        <input type="text" name="value" id="value">
        
        <button type="submit">
            <span>Send</span>
        </button>
        
    </form>
    

    Right after, manage your form with JavaScript like that (I am more concise than before. To do so, ACF really pissed me off.):

    
    <form id="mySuperForm" action=""  method="POST">
        
        <input type="text" name="key" id="key">
        <input type="text" name="value" id="value">
        
        <button type="submit">
            <span>Send</span>
        </button>
        
    </form>
    
    <script>
        const formElement = document.getElementById("mySuperForm");
        if(!formElement) return;
        
        
        /*
        * Recup field
        */
        const k = document.getElementById("key");
        const v = document.getElementById("value");
        
        /*
        * Create a variable for prevent multiple submits
        */
        let canSubmit = false;
        
        formElement.addEventListener("submit", (e) => {
                
            if(!canSubmit) return;
            
            /*
            * Prevent form to be automaticly submit on "Enter press" or button "Send" click
            */
            e.preventDefault();
            
            
            /*
            * Do your field verifications here
            *
            * Add an error CSS class when a field is not good ...
            */
            
            
            /*
            * If error found, return
            */
            if(formElement.querySelector(".error")) return;
            
            canSubmit = false;
            
            formElement.style.opacity = .6;
            formElement.style.pointerEvents = "none";
            
            
            /*
            * If no error, send with fetch.
            *
            * The ajaxurl variable exist from the back-end. You need to create it if you when play with ajax from front-end
            */
            const formData = new FormData();
            formData.append("action", "save-something");
            formData.append("key", k.value);
            formData.append("value", v.value);
            
            fetch(ajaxurl, {
                post: "post",
                body: formData
            })
            .then(resp => resp.json())
            .then(data => {
                
                canSubmit = true;
                
                formElement.style.opacity = 1;
                formElement.style.pointerEvents = "initial";
                
                console.log(data);
                
            });
            
            
        });
        
    </script>
    

    Ok cool, you send your data in the air, but you want play with it, do some verifications and save your data if all is good. Go in your functions.php and add this code. (don’t forget change $post_id by yours or by “option” and do your verifications):
    https://pastebin.com/P7CUpT1h

    If you put a look to my code, you see some wp_ajax_{action} hook…. with my first text, I explain that to you, but right now, sorry, but I don’t want. (Fuck ACF…)

    All done!

    Don’t hesitate if you have some questions 💪

  • Yo!

    I writen you a really nice tutorial from my hands, but ACF has block me because I take to much time or I don’t know and my text has been removed… Just wooow… Nice!

    Wait me!

  • You have multiple ways according to what you want to do.

    The most likely will probably be “Repeater Fields” from the Pro version.

    Content Flexible can work too depending your mindset.

  • Hello Drew!

    Please, give us the part of the code when you try update a field and give us more details about where is your field. Does it is from a group? A repeater ? Other? What is the exact structure?

    Best regards!

  • Hello Florence!

    Here is 2 possibilities.

    Hope this will help you!

    Option #1

    <?php
    
    /*
    * First option
    */
    $rows = get_field("my_repeat_name", "option");
    
    if($rows){
        foreach($rows as $row){
            echo $row["field_name"];
        }
    }
    
    ?>
    

    Option #2

    
    <?php
    /*
    * Second option
    */
    if(have_rows("my_repeater_name", "option")){
        
        while(have_rows("my_repeater_name", "option")) : the_row();
            
            echo get_sub_field("field_name");
        
        endwhile;
    }
    
    ?>
  • Hi Polyspora!

    In a while loop, get your sub field with get_sub_field('field_name') and not sub_field.

    You can direclty display your field with the_sub_field('field_name').

    Cheers!
    Sam

  • Your third subfield is a repeater too?

    If yes get your two repeater values that you want combinate, merge it and push it in your third part with update_field().

    If no, like John asked, we’ll need to know what’s the data you’ll merge and what’s the third field.

    Cheers
    Sam

Viewing 25 posts - 1 through 25 (of 26 total)