Support

Account

Forum Replies Created

  • Hi Jhon,

    Thanks for your answer. I want to change field for several reasons but one of them is I need to create statistic and in this specific case I can’t use your solution because it’s will be very too long to edit and save all our old post.

    For exemple I need to :

    • Change text to select field : To made statistic I need to change text field to a select one because user never wrote value the same way. So I need to edit all the value by meta_key and depending on keywords.

    I probabely can use your filter but did you know a solution to apply filter to all post (by PT for exemple) and save ? For exemple load mass change from a option page I create ?

    Appart from this your function is very usefull and I probably can edit it to fit for many case.

  • Hi Madjaeg,

    Exept by telling you to check if ‘the_field()’ is in a post loop it’s hard to identify and fix your issue with no page code.

    Because of you updated your PHP, WP and ACF at the same time your issue can be explain by PHP, WP or ACF syntaxe error…

    Can you put your complete page code? to allow us to identify what goes wrong.

  • Hi Florian,

    I think you will not find a solution by putting something else in ‘choices’ and I assume it’s not working because the exemple you followed is not for multiple select field. So you probably try to put an array somewhere a string is required.

    Use print_r to display your get_field result and find how to use it.

    If you don’t find the solution let’s us see your code because is not easy to find what’s exactly goes wrong with no code lines.

    Hope it’s help.

  • Hi Pipo,

    ACF store the subfield data in a very particulary way and it’s hard to use it directly on query but there is a filter provided by ACF to use subfield as meta-queries for WP_query here.

    But I suggest to you to use the John Huebner method to adapt and save your repeater as an array Metadata.

    It will be more efficient I think.

  • Hi,

    If i’m right, you just want to avoid user with back-end access to make change on ACF. I don’t know if you can disabled field editing on specific environnement (live and staging) but you can simply change the capability needed to access ACF editing with the ‘acf/settings/capability’ filter.

    I made the same for my website :

    1) Create a specific capability named ‘edit_acf’
    2) Set this specific capability as access rule for ACF with ‘acf/settings/capability’ filter
    3) Add the specific capability only to role/user you want

    This will not make your “staging ACF json” as “source of truth” but you’ll be sure that’s user can make change.

    Hope it’s solve your issue

  • Hi Himandev,

    It’s totally possible, the query method depend on the users field type.

    I assume your field type return user by ID. You have to query your score CPT with wp_query and metaqueries.

    If it’s a single post object field allowing only one user : use the wp_query with you field name as key and an equal criteria with the needed user ID.

    If it’s a single post object field allowing multiple user : use the wp_query with you field name as key and and In criteria with the needed user ID.

    If you have your user field in a repeater : I recomand you to follow the John Huebner method

  • Hi Kristjan,

    I see two way to do it depending on if you want your statut resume to be editable or not.

    If not : you can simply use the Enhanced Message Field plugin which allow you to put a ACF field containing HTML and PHP. In the field you’ll just have to get the post ID and use get_field and get_subfield to display the Kristijan resume as on front-end.

    If need it editable : I assume you can add a repeater field in the statut Tabs and use validate_value filter and prepare_field or load_value action to fill it. The validate_value filter on the resume statut field may allow you to synchro your first repeater.

    In the second case I haven’t the exact code solution because I never do the same but it’s a begining of help 🙂

  • Maybe the sort method doesn’t work … You can’t check here how to use the sort method.

    I assume you have text choices so you may have to add a sort flag (See in the link).

  • Hi Tringwebdesign,

    I think it’s not working because you try to save the $field[“choices”] in $field, try this :

    function sort_checkbox( $field ) {
    	$field["choices"] = sort($field["choices"]);
    	return $field;   
    }
    add_filter('acf/load_field/key=field_5d4164d40898f', 'sort_checkbox');

    I assume the sort method you use is correct, it’s may not.

  • Hi Javadth,

    Sorry for the delay. You can add simply a <br> the way below:

    <?php
    $field = get_field_object('sors');
    $value = $field['value'];
    if (!empty($value)){
        echo '<p>'.$field['label'].' : <br> '.$value.'</p>';
    }
    ?>
  • I solved the tropic by myself (and with the Help of John based on another tropics), so if someone had the same issue :

    // Add a AJAX action to get attachement URL by ID in JS
    add_action( 'wp_ajax_get_media_url', 'get_media_url' );
    add_action( 'wp_ajax_nopriv_get_media_url', 'get_media_url' );
    function get_media_url() {
    	if ( isset( $_POST['att_id'] )) {
    		$attachement_id = $_POST['att_id'];
    		$attachement_url = wp_get_attachment_url( $attachement_id );
    		echo $attachement_url;
    	} else  {
    		echo '#';
    	}
    	wp_die();
    }
    // JS to add the download link
    function acf_gallery_download_link() {
    	if ( !is_admin() ) { return; }?>
    	<script type='text/javascript'>
    			( function ( $ ) { $( document ).ready( function () {
    				// Add download link to attachement on hover
    				$('.acf-gallery-attachment').each(function(i, item){			
    					var attachement_id = $(this).attr("data-id");
    					var data = {
    					     'action': 'get_media_url',
    					     'att_id': attachement_id,
    					};
    					$.post(ajaxurl, data, function(response){
    						var attachement_url = response;
    						$(item).children(".actions").children(".acf-gallery-remove").before('<a class="acf-icon -see dark" href="'+ attachement_url +'" target="_blank" data-id="'+attachement_id+'" title="Toto">Toto</a>');					
    					});				
    				});
    				// Add download link to gallery side data
    				acf.addAction('append', function( $el ){
    					var attachement_id = $el.find(".actions").children(".acf-gallery-edit").attr("data-id");
    					var data = {
    						'action': 'get_media_url',
    						'att_id': attachement_id,
    					};
    					$.post(ajaxurl, data, function(response){
    					     var attachement_url = response;
    					     $el.find(".actions").children(".acf-gallery-edit").before('<a href="'+ attachement_url +'" target="_blank" class="acf-gallery-see" data-id="'+attachement_id+'">See</a>');					
    					});		
    				});
    			});
    		}( jQuery ) );
    	</script>
    <?php}
    add_action( 'admin_footer', 'acf_gallery_download_link' );
  • Hi John,

    I needed a looooong time to solve the entire issue but the JS API append action is exactly what I was looking for.

    If someone want the complete solution I use in a PHP function file :

    // Add a AJAX action to get attachement URL by ID in JS
    add_action( 'wp_ajax_get_media_url', 'get_media_url' );
    add_action( 'wp_ajax_nopriv_get_media_url', 'get_media_url' );
    function get_media_url() {
    	if ( isset( $_POST['att_id'] )) {
    		$attachement_id = $_POST['att_id'];
    		$attachement_url = wp_get_attachment_url( $attachement_id );
    		echo $attachement_url;
    	} else  {
    		echo '#';
    	}
    	wp_die();
    }
    // JS to add the download link
    function acf_gallery_download_link() {
    	if ( !is_admin() ) { return; }?>
    	<script type='text/javascript'>
    			( function ( $ ) { $( document ).ready( function () {
    				acf.addAction('append', function( $el ){
    					var attachement_id = $el.find(".actions").children(".acf-gallery-edit").attr("data-id");
    					var data = {
    						'action': 'get_media_url',
    						'att_id': attachement_id,
    					};
    					$.post(ajaxurl, data, function(response){
    					     var attachement_url = response;
    					     $el.find(".actions").children(".acf-gallery-edit").before('<a href="'+ attachement_url +'" target="_blank" class="acf-gallery-see" data-id="'+attachement_id+'">See</a>');					
    					});		
    				});
    			});
    		}( jQuery ) );
    	</script>
    <?php}
    add_action( 'admin_footer', 'acf_gallery_download_link' );
  • Hi Samanthaleigh,

    Can you give us more information ? The code you used to create the CPT, screenshot of your field group setting, …

    It’s hard to find where the issue is with no details.

  • Hi WDCreativ,

    I’m not sure about what you need, you’re talking about displaying a field group to logged in user and about showing post content which was assigned to the user. Can you tell me more ?

    What do you want to display : CPT Content ? Field Group ? …
    Where : In backend ? Frontend ? On user profile ? On CPT ? …
    With wich rules : Display it if you assign user to the CPT ? When user select the CPT ID with the select field ? …

  • Hi Javadth,

    If you want to echo the label (and the value) only if $field[‘value’] is not empty you can do this way :

    <?php
    $field = get_field_object('sors');
    $value = $field['value'];
    if (!empty($value)){
        echo '<p>'.$field['label'].' : '.$value.'</p>';
    }
    ?>

    Hope it’s help.

  • Hi Nox,

    Yes I sent you an answer, not visible here … Weird. I don’t know if you get me answer by email even if it isn’t visible here ? What matters is you get your solution =)

    For the first issue, yes you’re right, we can assume “ACF finally asigned an empty string (and not a null value) in the meta key” because as I try to tell in my “ghost answer” the ‘NOT EXISTS’ operator means the metadata isn’t set or is set to null. When you have this kind of issue the best way is to test your metadata this way (use it in single_post.php for exemple) :

    if( ! in_array( 'date_sale', get_post_custom_keys( $post_id ) ) ) {
        Echo ‘The metadata isn’t set, the NOT EXISTS operator must works’; 
    } else {
        $my_sale_date_meta = get_post_meta($post_id, ‘date_sale’);
        If(is_null($my_sale_date_meta)){
            Echo ‘The metadata is null, the NOT EXISTS operator must works’;
        } else {
            Echo ‘The metadata is set and not null, the NOT EXISTS operator can\’t work’;
        }
    }

    For your second issue, I assume your first arguments doesn’t works because your ‘date_sell‘ format isn’t comparable to the $date_limit format. If you have another issue like this, the best way to find an answer is to print your arguments using native WP or PHP function (not ACF one which may “traduce” the metadata depending on field settings).

    Have a good coding day !

  • Hi Nox,

    For your first question : the ‘NOT EXISTS’ operator means the metadata isn’t set or is set to null. So to understand why this operator doesn’t work in your case you can try this in the single_post.php (just to testing it):

    if( ! in_array( 'date_sale', get_post_custom_keys( $post_id ) ) ) {
    Echo ‘The metadata isn’t set, the NOT EXISTS operator must works’; 
    } else {
    $my_sale_date_meta = get_post_meta($post_id, ‘date_sale’);
    If(is_null($my_sale_date_meta)){
    Echo ‘The metadata is null, the NOT EXISTS operator must works’;
    } else {
    Echo ‘The metadata is set and not null, the NOT EXISTS operator can\’t work’;
    }
    }

    If you echo “… the NOT EXISTS operator must works” that’s means another part of your code make it wrong, else, it’s perfeclty normal it’s not working in your case because even if your field is empty the metadata is set and not null.

    For your second issue, you have to process some testing too : Are you sure the metadata date_sale can be compared to you $date_limit ? Use the get_post_meta() to print your date_sale, but it’s possible that your date_sale return a string which can’t be compared to a DateTime. In that case you must convert your date_limit to a comparable format

    Hope it’s help.

  • Hi Soph,

    If you want to sort your repeater in frontend or in backend there is an ACF documentation here.

    Tell me if you need help to use it for your own case.

  • Hi Byrd,

    You’re right : Because of your ‘location’ data is in subfield you can’t query post by using it as meta_query (to be honest you can but by using an ugly solution).

    I had the same issue with a repeater subfield and I got a very helpfull advice from John Huebner : See my post here.

    To resume : Use the ‘save_post’ filter on your event CPT to save with add_post_meta the location as simple metadata (For example : ‘wp_location’). Then you’ll be able to easily query it.

  • Hi,

    (The solution below is for front-end page use)

    If your custom field on page A (which contain the link to the page B) is not a repeater field you can simply use the ‘WP_Query‘ with meta_query on PageA to get all page where you custom field is equal to you current page link.

    Because the query will return page IDs, you can get all the pageA cutom field values.

    Hope it’s help. ASk if you need more details.

  • Hi Dave,

    You can add setting to field by using the ‘acf/render_field_settings’ filter but I don’t know how to change the setting value on post save. I don’t think it’s the best solution but, according to the function I already used, this may works :

    1. Use the ‘prepare_field’ filter on one (or all) subfield to add a class (for example ‘saved_in_database‘) if the field[‘value’] is not empty.
    2. Add some JQuery with the ‘admin_footer‘ action to remove the “remove button” on the same row.

    To explain a bit more my proposal : The ‘prepare_field’ filter works when the value is already loaded from database, so if the field[‘value’] is not empty that’s means the row was already saved. By adding a class on your repeater subfields which are already saved in database you create some JQuery target. By using the ‘.closest()‘ and ‘.child()‘ Jquery method you can finaly target the ‘‘ of the rows which contain at least one saved subfield and ‘.remove()‘ it.

    Hope it’s help. Tell me if you need some code example.

  • Hi Eric,

    Your first issue : write month in French it’s not an ACF issue but a PHP one because you use ‘DateTime()‘ an ‘format‘ and this only works in English. If you want to get the month in French you can :

    • Create an array to traduce the month yourself
    • Convert your ‘DateTime()‘ into ‘Timestamp‘ to use ‘strftime‘ and a ‘setlocale()

    For the first solution, the exemple :

    Traduce_Month = array (
         "January" => 'Janvier', 
         "February" => 'Fevrier', 
          ...
    )
    echo '<h4 class="blanc">' .Traduce_Month[$monthKey]. ' ' . $yearKey . '</h4>';

    For the second one you can find all the documentation needed in PHP codex by searching ‘strftime‘ and ‘DateTime::createFromFormat‘ (to convert you date).

    For your second issue (still a PHP issue), to write the event date you just have to get the $date value you saved in your array ‘$group_posts[$year][$month][]‘ and echo it by using ‘$date->format‘ as you already done.

    Hope it’s help

  • Hi Proacfelie,

    It’s totally possible, the right way (and the easier way) to do it depends on what you exacly need : Display relationship on frontend / backend ? Do you used simple relations field or in repeater ?.

    If your in the worst case, Designer and Project posts have both several relationship in repeater and you want to edit and display in backend and frontend (hope it’s will be understandable) :

    Use the WP save_post action. If you save a Project ( Do with If and get_post_type()) loop on your “Designer” repeater field, and for each “Designer” input you found get and loop on the “Project” repeater field of your Designer post. If the project is already in do nothing, otherwise use acf function to update the field and add a new “Project” row. Do the same when want to save the Designer name in the Project post when saving a Designer post.

    There are proper ways to do it if you don’t need the two repeater and/or if you want to query post based on repeater field key.

    If you need other solution or code example tell it.

  • Hi Pipoulito,

    You have two solutions i’m familliar with to do it dynamically:

    • Using Javascript to change the “PIECE” choice by using the WP ‘admin_footer’ action to put some javascript in backend.
    • Create several “PIECE” fields and use the logical condition in the field settings to display the good one depending on the “TYPE” value.

    It depend on you.

  • Hi Zekmek,

    I don’t understand what you want to do, can you give us more information ? more code ?
    Your code is very simple and seams to be correct so the mistake is probabely around this code.

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