Forum Replies Created

  • Shortcodes are meant to return data instead of echo it out. Additionally, it looks like the concatenation is malformed after $link1. Any time you’re combining variables with strings you need to use period . to connect them and only a semicolon at the very end. The variables are also not right – you use ‘price1’ in for the field parameter but $go_price is the variable. The anchor needs double quotes to surround the attribute URL. And the conditional needs 2 ampersands.

    All in all it should look something like this:

    function displayprice() {
    	$return		= '';
    	$go_price 	= get_field( 'price1' );
    	$go_link 	= get_field( 'link1' );
    	if( $go_price && $go_link ) {
    		$return = '<a href="' . esc_url( $go_link ) . '">' . $go_price . '</a>';
    	return $return;
    add_shortcode( 'showprices', 'displayprice' );
  • Hopefully you’re not trying to update based off the invented post ID – If you can you should let WordPress create IDs for new posts ( which it does in MySQL ) otherwise you’ll surely run into issues down the road.

    Difficult to suggest the best course of action without the context of the rest of the code block.

  • I copy and pasted the code supplied in your Stack Overflow question, changed the single quotes to double quotes, changed the ‘to’ email, and saved the code as a custom 1 file plugin. It worked as expected, I received the user field in the email sent.

    If you’re not getting it in your email then there’s something not provided that we’re missing or the data isn’t saved into the usermeta table.

  • This may be a silly question but are you sure your <form> tag has method="post" set? I was under the assumption you have a custom <form> wrapper to include you custom inputs along with an acf_form() with a field group of inputs. It may be easier to replicate and debug given the full form code.

    If you figure out the issue though be sure to come back and let us know!

  • As far as I know it should be the same throughout all versions. You could turn on error log debugging and use the acf/save_post hook to error log your $_POSTed values and see where your fields are:

     * Error log processing ACF form saves
     * @param Mixed $post_id
     * @return void
    function prefix_acf_save_post( $post_id ) {
    	// Don't run on the admin panel, front-end forms only
    	if( is_admin() ) {
    	error_log( sprintf( 'Front-end Save Post: %1$s', $post_id ) );
    	error_log( print_r( $_POST, 1 ) );
    add_action( 'acf/save_post', 'prefix_acf_save_post', 9 );
  • Can you show your code for the front-end form? If you’re creating a new post, post_id will actually be a string of ‘new_post’ and will always fail the first few conditionals. Additionally, it could pick up the global $post of the page that the form is on which may not align with what you’re trying to do.

  • Can you verify it’s being saved in the database as in the usermeta table?

  • Could you explain how you registered this taxonomy? Odds are it’s not a public taxonomy for one reason or another and it’s being excluded from the list.

  • I think the problem is your use of single quotes where there should be double quotes:

    get_field( 'user_phone', 'user_{$user_id}' )

    Should be

    get_field( 'user_phone', "user_{$user_id}" )

    I’ve left an answer on your post.

  • As a user of ACF I feel that that’s out of scope of what Advanced Custom Fields does. If the link goes to an external website then you would need to run some Javascript and AJAX to update a counter value.

  • I’m certainly not the authority of such a thing but this sounds like a feature for when Advanced Custom Fields 5 first hit the shelves – that’s what it seems like from the blog post. If you’ve been getting regular updates – ACF is a few versions into 5 and it’s definitely stable enough so it’s probably unnecessary to have it at this point.

  • It too confused me at first since the filter kind of sounds like it’s editing the active toolbar but in the documentation of the hook it says:

    Once a new toolbar is added to the list, it will then appear in the WYSIWYG field’s options when editing the field group.

    So I added the code in your question and sure enough if I go back to edit the Field Group in Custom Fields there’s a new radio button on the WYSIWYG Field labeled ‘Very Simple’ and when selected will only display a toolbar with bold, italic, and underline buttons on it.

  • Is this on the front-end or backend? Could you check against has_term() or $_POST?

  • I’m assuming you mean on the front-end / display end and not the admin panel. If I’m mistaken please reply back and we can come up with a different solution. Additionally I don’t have Pro but from what I remember the repeater field is simply an array so instead of using the helper functions you can get the raw results using get_field().

    // Get our repeater values
    $repeater_arr = get_field( 'repeater-name-or-key', $post_id );
     * We're going to shuffle the repeater array ( randomize the whole thing )
     * Which is done by reference, so lets put it in a temporary value
     * So we don't mess with our original repeater_arr value
    $temp_arr = $repeater_arr;
    shuffle( $temp_arr );
    // Grab up to 10 values of the array
    $random_slice = array_slice( $temp_arr, 0, 10 );
    // Loop through the random subfields
    foreach( $random_slice as $subfield ) {
    	echo $subfield['title'];
  • You should still be able to use acf_form() ( similar to how you would a front-end from ) tell it not to display the form just the fields:

    Even though it’s not on the front-end it’s still a way to get a Field Group into a custom form:

    acf_form( array(
    	'form' 			=> false,
    	'field_groups' 	=> array( 'acfieldgroupkeyhere' ),
    ) );

    You would still need to call acf_form_head() to get the neat functionality and styles ACF provides. The biggest problem with this is that the fields are POSTed into an array $_POST[‘acf’] and keyed by the Field IDs instead of the field names – you can either either keep track of the field IDs in your code and what ID gets saved where or you can loop through the ACF fields array by Key to get the name using get_field_object( $key ).

  • A couple questions:

    1) Do you mean on the front-end, you’re unsure how to check against the selected radio button?

    IF you’re asking questions about the Admin Panel…

    2) Are these things ( radio buttons, images ) all part of the same Field Group?

  • I wouldn’t think so. If you want to make a table, a traditional table plugin would be a better solution as it will end up being more user friendly and easier to work with than an extremely large repeater field. Try one of the below plugins or check the WordPress repository:


    Advanced Custom Fields: Table Field Plugin

    All being said it’s just my opinion.

  • I get what you’re trying to do, and I’ll post the code below with how to do it using a flat array but it’s unclear what the_query is or how it relates to Advanced Custom Fields. Until the actual code you’re using is posted the below may be a good starting point for you:

    $image_array = query(); // Whatever you're using to query the images
    // Ensure have an image array to work with
    if( ! empty( $image_array ) ) { 
    	$per_block   = 4;
    	$total_items = count( $image_array );
    	foreach( $image_array as $index => $image_id ) {
    		$nice_index = $index + 1;		// Arrays start at 0 but count and per block start at 1. Calculate once.
    		$start = ( 0 == $index % 4 );	// Calculate if we're at the start
    		$end   = ( $nice_index == $per_block || $nice_index == $total_items );	// Check if we've hit the end
    		// Display Opening Tag
    		if( $start ) {
    			print( '<div class="col-md-3">' );	
    			// Display image by ID
    			wp_get_attachment_image( $image_id, 'full' );
    		// Display Closing Tag
    		if( $end ) {
    			print( '</div>' );
    	} // END Foreach
    } // END Conditional
  • You should be able to hook into the admin footer and add in any kind of datepicker option as you need by field ID:

     * Modify ACF Datepicker Formatted Field
     * @return void
    function theme_prefix_admin_footer() {
    			jQuery( document ).ready( function( $ ) {
    				let $datepicker = $( '#acf-field_5b16a9d5df47c + .hasDatepicker' );
    				$datepicker.datepicker( 'option', {
    					altFormat: 'dd. M yy'
    				} );
    			} );
    add_action( 'admin_footer', 'theme_prefix_admin_footer' );
  • As far as I can tell in the latest stable version of ACF this is no longer an issue. Whether or not it was the code above or something else I wouldn’t be able to say. I would suggest just downloading the latest stable version though and going with that 🙂

  • I can’t say for certain if this is the issue but you have an outer loop which is the main loop and holds the Global $post object. You then have an inner loop with a foreach(). Whenever you call the_field() it will always pull from the Global $post object unless told otherwise. Your foreach() doesn’t overwrite this ( you would need to use setup_postdata( $slide ) ).

    The solution could be, assuming you want to pull field values from the get_posts() results is to pass the post or post ID into the function call like so:

    the_field( 'main_slide_title', $slide )


    the_field( 'main_slide_title', $slide->ID )

  • I’m not sure I follow. You’re using the Relation field using Small Businesses are your primary Field and on your other 3 post types it’s just repeating the same small business title multiple times?

    Maybe it would be easier for the explanation to simplify this ti Post Type A and Post Type B and describing what field you’re using, what settings you’re using for the field, what is happening and what you expect to happen.

    The above may make it easier for those here helping to replicate the issue and give you the best advice on how to proceed.

  • It looks like that issue is solved. There’s no reason for the code in that answer to return a string whenever it’s being casted as an integer which means something else is causing the string casting.

    You would need to show your full code for us to be of any assistance.

  • I’m not sure if ACF has a field like this ( not that I could see in the basic version anyway ) but this type of thing would work best as a Non Hierarchical Taxonomy with a Select2 type field. Think post tags: it’s searchable, you can assign multiple, and it’s listed out in a formatted easily manageable input for the user to digest. You can control whether the user will be able to create new terms or only select from existing terms. You can populate with AJAX and give them a populated list of options. It seems to make sense for the usecase described.

    Terms is pretty efficient when querying because of the relational tables already setup. A custom table and query may be more efficient but would also be more work to setup.

  • I think the core issue is when dealing with pure local json fields and calling get_field() by name will attempt to check postmeta for the field key. If you call get_field() using the field key, it pulls from local JSON just fine. The solution was looking through local fields for a match – not perfect but works in my usecase:

Viewing 25 posts - 26 through 50 (of 62 total)