Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • @deuxparquatre

    I see. Is it easy to convert admin pages to acf option pages?

  • 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.

  • I have found that if I go to the record with null value from the above function and click UPDATE and then go back and run the above function, the number is there. It is like the number is there but isn’t at the same time. Just wondering what could possibly be the problem.

    When this happens it is usually because the field was updated incorrectly. If a field is updated using update_field() and the field for the post it is attached to does not have a value in the database then you must use the field key when calling update_field(). You cannot use the WP function update_post_meta() or any equivalent function to update fields that do not already exist in the database. If you do then you must also add the field key reference to the database yourself.

    See this section of the update_field() documentation for an explanation of field key reference https://www.advancedcustomfields.com/resources/update_field/#updating-via-field-key

  • 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/

  • @drew321

    Is there a post id for custom admin menu pages? When I look at the url, all it says is page=<page name>

    Is this an ACF options page that we’re talking about? If yes then the post ID would be “options” or whatever you used for post_id when adding the options page.

  • Interesting. This is the record BEFORE I go to the backend and hit update.

    {
    “osm_geometry”: “way/955280979”,
    “fs_ski_resort_name”: “牧の入高原スノーパーク”,
    “fs_ski_resort_name_en”: “Makinoiri Kogen Snow Park”,
    “fs_ski_resort_landuse”: “winter_sports”,
    “fs_ski_resort_sport”: “downhill”,
    “fs_ski_resort_lit”: null,
    “fs_ski_resort_email”: null,
    “fs_ski_resort_phone”: null,
    “fs_ski_resort_fax”: null,
    “fs_ski_resort_addr_full”: null,
    “fs_ski_resort_postal_code”: null,
    “fs_ski_resort_contact_website”: “https://makinoiri.com/&#8221;,
    “fs_ski_resort_contact_facebook”: null,
    “fs_ski_resort_contact_twitter”: null,
    “fs_ski_resort_wikidata”: null,
    “fs_ski_resort_wikipedia”: null,
    “fs_ski_resort_aa_winter_sports_sq_km”: “0.74”,
    “fs_ski_resort_aa_pistes_length”: “5660”,
    “fs_ski_resort_aa_lifts_length”: “2520”,
    “fs_ski_resort_aa_pistes_count”: “12”,
    “fs_ski_resort_aa_lifts_count”: “4”,
    “fs_ski_resort_aa_min”: “610”,
    “fs_ski_resort_aa_max”: “891”,
    “fs_ski_resort_aa_novice_length”: “0”,
    “fs_ski_resort_aa_novice_count”: “0”,
    “fs_ski_resort_aa_easy_length”: “0”,
    “fs_ski_resort_aa_easy_count”: “0”,
    “fs_ski_resort_aa_intermediate_length”: “0”,
    “fs_ski_resort_aa_intermediate_count”: “0”,
    “fs_ski_resort_aa_advanced_length”: “0”,
    “fs_ski_resort_aa_advanced_count”: “0”,
    “fs_ski_resort_aa_expert_length”: “0”,
    “fs_ski_resort_aa_expert_count”: “0”,
    “fs_ski_resort_aa_freeride_length”: “0”,
    “fs_ski_resort_aa_freeride_count”: “0”,
    “fs_ski_resort_aa_extreme_length”: null,
    “fs_ski_resort_aa_extreme_count”: null,
    “fs_ski_resort_aa_zoom”: null,
    “fs_ski_resort_aa_y”: “36.8143696397”,
    “fs_ski_resort_aa_x”: “138.3968575196”,
    “fs_ski_resort_aa_mean”: “192.00350194703”,
    “fs_ski_resort_aa_pitch”: null,
    “ZOOM”: null
    },

    This is the output after I hit the UPDATE button. The info is sitting populated in the input boxes. Strange.

    {
    “osm_geometry”: “way/955280979”,
    “fs_ski_resort_name”: “牧の入高原スノーパーク”,
    “fs_ski_resort_name_en”: “Makinoiri Kogen Snow Park”,
    “fs_ski_resort_landuse”: “winter_sports”,
    “fs_ski_resort_sport”: “downhill”,
    “fs_ski_resort_lit”: “”,
    “fs_ski_resort_email”: “”,
    “fs_ski_resort_phone”: “”,
    “fs_ski_resort_fax”: “”,
    “fs_ski_resort_addr_full”: “”,
    “fs_ski_resort_postal_code”: “”,
    “fs_ski_resort_contact_website”: “https://makinoiri.com/&#8221;,
    “fs_ski_resort_contact_facebook”: “”,
    “fs_ski_resort_contact_twitter”: “”,
    “fs_ski_resort_wikidata”: “”,
    “fs_ski_resort_wikipedia”: “”,
    “fs_ski_resort_aa_winter_sports_sq_km”: “0.74”,
    “fs_ski_resort_aa_pistes_length”: “5660”,
    “fs_ski_resort_aa_lifts_length”: “2520”,
    “fs_ski_resort_aa_pistes_count”: “12”,
    “fs_ski_resort_aa_lifts_count”: “4”,
    “fs_ski_resort_aa_min”: “610”,
    “fs_ski_resort_aa_max”: “891”,
    “fs_ski_resort_aa_novice_length”: “0”,
    “fs_ski_resort_aa_novice_count”: “0”,
    “fs_ski_resort_aa_easy_length”: “0”,
    “fs_ski_resort_aa_easy_count”: “0”,
    “fs_ski_resort_aa_intermediate_length”: “0”,
    “fs_ski_resort_aa_intermediate_count”: “0”,
    “fs_ski_resort_aa_advanced_length”: “0”,
    “fs_ski_resort_aa_advanced_count”: “0”,
    “fs_ski_resort_aa_expert_length”: “0”,
    “fs_ski_resort_aa_expert_count”: “0”,
    “fs_ski_resort_aa_freeride_length”: “0”,
    “fs_ski_resort_aa_freeride_count”: “0”,
    “fs_ski_resort_aa_extreme_length”: “”,
    “fs_ski_resort_aa_extreme_count”: “”,
    “fs_ski_resort_aa_zoom”: “15”,
    “fs_ski_resort_aa_y”: “36.8143696397”,
    “fs_ski_resort_aa_x”: “138.3968575196”,
    “fs_ski_resort_aa_mean”: “192.00350194703”,
    “fs_ski_resort_aa_pitch”: “85”,
    “ZOOM”: “15”
    },

  • Hi @deuxparquatre, thanks for the indepth post! I have a quick question on the ajax part. I am unfamiliar with the fetch function. Is that a php or wordpress function?

  • Oh dang, I just hopped back and saw the posts and currently reading through! So I have a quick question on the postid for update_field. Is there a post id for custom admin menu pages? When I look at the url, all it says is page=<page name>. I don’t see a numerical value that would correlate to a post id.

  • @deuxparquatre I can see all the post, all posts should now be visible to everyone. If there is one missing then it does not exist.

    The simple answer to the OP and their original code is that the post ID is required when using update_field() in the manner that it is being used because ACF cannot detect the correct post ID when using a form created outside of ACF.

  • Woah so cool, thank you! I understand what I did wrong now 😀
    I changed the code slightly to make it simpler:

        if(have_rows("gesloten", "option")){
            
            echo '<table style="width: 100%;">';
            
                echo '<tbody>';
            
                while(have_rows("gesloten", "option")) : the_row();
    
                    $feestdag = get_sub_field("feestdag");
    
                    $datumgesloten = get_sub_field("datum");
                    
    
                    echo '<tr>';
                        echo '<td>'. $feestdag .'</td>';
                        echo '<td>'. $datumgesloten .'</td>';
                    echo '</tr>';
    
                endwhile;
            
                echo '</tbody>';
            
            echo '</table>';
        }
    
    ?>

    One last question. How can I style the columns to 50%?
    I tried adding a width=”50%” inside <td> but that did not get me the desired look.

    The top table is how I would like it to look. The bottom table is the current output.

    Tbale column spacing

    Thank you much for this

  • 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>';
        }
    
    ?>
    
  • Hello Sam, thank you! I created a shortcode using WP Code plugin with the code below:

    if(have_rows("gesloten", "option")){
        
        while(have_rows("gesloten", "option")) : the_row();
            
            echo get_sub_field("feestdag");
            echo get_sub_field("datum");
            echo get_sub_field("eind-datum");
        
        endwhile;
    }
    
    ?>

    1. How can I now display these fields in the manor I suggested?
    2. There is one field that may sometimes be empty “eind-datum”. If empty, nothing should be shown. Also the dash in front of that date should not be shown. The output should like something like this:

    text-field 12/12/23 – 14/12/23
    text-field 16/12/23
    text-field 19/12/23 – 22/12/23
    text-field 27/12/23
    text-field 29/12/23

    Thank you!

  • 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 💪

  • Thanks for responding Sam! So I’m currently trying to update the field with text input from a key and value input text box when a submit button is being pressed in an admin menu page. The field I’m trying to update is a text area. Here is the code:

    	    <form action=""  method="POST">
                <input type="text" name="key" id="key">
    	    <input type="text" name="value" id="value">
                <input type="submit" name="Submit" value="send" >
                </form>
    
                    <?php
    		if(isset($_POST['Submit']))
    		{
    			$key = $_POST["key"];
    			$value = $_POST["value"];
                            $array = array($key,array($value));
                            $out = json_encode($array);
    			update_field('field_key',$out);
    		}
    		?>
  • 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;
    }
    
    ?>
  • Ended up cheating by using this:

    
    $image_meta_image_id = $_GET["image_id"];
    global $wpdb;
    $attachment_query = "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = 'image_meta_image_id' AND wp_postmeta.meta_value = '" . $image_meta_image_id . "' ) ) AND wp_posts.post_type = 'attachment' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1";
    $attachments = $wpdb->get_results( $attachment_query );
    

    Still unsure why the WP query doesn’t work, but this is good enough. Thanks for the help.

  • Thanks John, but i really don’t understand what i have to do. I’m not familiar with SQL query

    All my others custom field users work perfectly, this is just with the repeater the problem, did i have to change all the query ?

    i really don’t understand the pre_user_query and the impact on my all code :/

    can you explain little bit more please ?

  • Oh man, yes, that’s it.

    <?php if(get_field('profile_mail', $employee->ID)): ?>
        <div class="profile__mail">
            <a href="mailto:<?php echo get_field('profile_mail', $employee->ID); ?>" class="profile__link">
                <?php echo get_field('profile_mail', $employee->ID); ?>
            </a>
        </div>
    <?php endif; ?>

    Thanks a lot.

  • My solution so far, in case anyone needs this:

    1. Install the plugin ACF Quick Edit Fields
    2. Create a new ACF field with your values
    3. Allow Bulk Edit in the new field (after you save it)
    4. Allow Filter by on the old field value
    5. Filter by the old values and Bulk Edit posts and assign the new value.

  • the hook you are using “posts_where” is for altering the WHERE clause of a post query. This will not work for a user query. WP has no hooks to alter the user query in this manner.

  • Hi

    The method is already working ?

    i tried.. and it dont work :/

    What i made :

    i got a custom field form, who search in ajax with get_users and with complexe request on many user’s customs fields

    all work fine, even filter taxonomy assigned to user like custom field

    but this dont work for my repeater field..

    the repeater key is : liste_des_langues & the item key : langue

    if add this :

    function wpza_replace_repeater_field( $where ) {
        $where = str_replace( "meta_key = 'liste_des_langues_$", "meta_key LIKE 'liste_des_langues_%", $where );
        return $where;
    }
    add_filter( 'posts_where', 'wpza_replace_repeater_field' );

    and this is my request args for this field :

    if($langues && $langues != 'all'){
            $temp = array(
                'key' =>  'liste_des_langues_$_langue',
                'value' =>  $langues,
                'compare' => 'LIKE',
            );
            array_push($request['meta_query'] , $temp);
        }

    this is the basic request :

    $request = array(
            'role__in' => array( 'consultant' ),
            'meta_query'      => array(),
            'tax_query'      => array(),
        );
    
        if(count($_GET) > 1){
            $request['meta_query']['relation'] = 'AND';
        }

    and i dont understand where is my mistake, someone can help please ?

  • So I must not be explaining clearly. The child theme’s field group has been changed from the parent theme. The parent theme and the child theme each depend on their own fields in this group. The problem is this field group’s key id is the same in each json file.

    example:
    parent_theme/acf-json/group_5d28b22d3fdc0.json -> unique fields

    child_theme/acf-json/group_5d28b22d3fdc0.json -> unique fields

    The initial developer must have modified the fields in the child theme, which worked initially, but now only the parent theme fields are loading in the child theme.

    I’m trying to get the child theme field groups to work properly again. But I don’t know where to start because the field group keys are the same in the parent and child themes.

  • Ugh…sorry. Had that and still no go:

    
      $args = array(
          'fields' => 'ids',
          'posts_per_page'    => 1,
          'post_type'      => 'attachment',
          'post_status' => 'any',
          'meta_query'    => array(
        		array(
        			'key'	 	=> 'image_meta_image_id',
        			'value'	  	=> $image_meta_image_id
        		)
        	)
      );
      $attachment_query = new WP_Query( $args );
      $attachments = $attachment_query->posts();
    
    
  • Just adding onto here since this is the code I use on my website;
    Is it possible to address this code to multiple custom posts types?
    E.g. I have custom post types called ‘tv’ and ‘radio’, but I think it wouldn’t be wise to repeat the entire code in the functions.php.

    Sorry if the question seems dumb but I know next to nothing about php.

Viewing 25 results - 3,176 through 3,200 (of 21,345 total)