Support

Account

Forum Replies Created

  • I think it would be beneficial to use the native WP UI for this, if possible, with its standard set of features and familiar design. The ACF select fields with a full list of posts are a bit heavy.

    Just a thought: there could be an option, as there is for images, to choose how the output will be formated – as HTML or as an array.

    โ€œcan you add a way to browse to external links to select themโ€

    Fantastic idea, haha.

  • Try using the category’s ID:

    $citrusID = 123;
    $variablew2 = get_field( 'parftestinfo', 'category_' . $citrusID );

    How to Get Values From a Taxonomy Term

  • 1) To obtain a specific row by the value of its subfield, you have to iterate through all rows.

    function retrieve_row( $fieldNameOrArray, $subfieldName, $searchValue, $post_id = false ) {
    	
    	if ( is_array( $fieldNameOrArray ) )
    		$field =& $fieldNameOrArray;
    	else
    		$field = get_field( $fieldName, $post_id );
    	
    	if ( !$field || !is_array( $field ) || !isset( $field[0][ $subfieldName ] ) )
    		return false;
    	
    	foreach ( $field as $index => $row ) {
    		if ( $row[ $subfieldName ] == $searchValue )
    			return $row;
    	}
    	
    	return false;
    	
    }
    
    // Example
    $row = retrieve_row( 'repeaterFieldName', 'uniqueId', 'gold' );
    // Or if you already have the field loaded into a variable
    $row = retrieve_row( $repeaterFieldArray, 'uniqueId', 'gold' );

    To enforce unique values in a particular subfield, you need to place a script on the repeater field’s instructions:

    <script>
    jQuery( function() {
    	
    	// Definitions
    	
    	var repeaterFieldName = 'repeater',
    		uniqueFieldName = 'unique_id',
    		$repeaterFieldEl = jQuery( '.field.field_type-repeater[data-field_name="' + repeaterFieldName + '"]' );
    		
    	// Validation
    		
    	jQuery(document).on( 'acf/validate_field', function( event, $el ) {
    		
    		var fieldName = $el.data('field_name'),
    			fieldValue,
    			$uniqueFieldList,
    			$uniqueInputs;
    			
    		if ( fieldName != uniqueFieldName )
    			// Skip fields other than the unique one
    			return;
    		
    		fieldValue = $el.find('input[type=text], input[type=number]').val();
    		
    		if ( !fieldValue )
    			return;
    		
    		$uniqueFieldList = $repeaterFieldEl.find( '.row > .sub_field[data-field_name="' + uniqueFieldName + '"]' );
    		$uniqueInputs = $uniqueFieldList.find('input[type=text], input[type=number]');
    		
    		// Compare against other unique fields
    		$uniqueInputs.each( function( n, currentEl ) {
    			if ( $uniqueFieldList[n] === $el[0] ) {
    				// Skip comparing against self
    				return;
    			}
    			if ( currentEl.value == fieldValue ) {
    				// Not unique
    				$el
    					.data( 'validation', false )
    					.data( 'validation_message', 'This field must have a unique value.' );
    			}
    		});
    		
    	});
    	
    });
    </script>

    Just set the repeaterFieldName and uniqueFieldName at the beginning to something appropriate, and make sure that your unique field is required, or the validation will not run.

    2) Perhaps you should create another ACF group with those same fields and associate it to users. Now the fields will exist in the user meta. When you use update_field(), pass the field name, not the key, as the key is going to be different.

  • Accessing the original file path in the user’s computer is not possible, either through JavaScript or PHP’s $_POST, because it would pose an invasion to the user’s privacy.

    You can only access the file’s name and a few other properties after it already has been uploaded, using the $_FILES superglobal on your PHP script.

    You then have to complete the upload process by moving/renaming the uploaded file (which is stored in a temporary folder) into your chosen directory, otherwise it will be automatically deleted by PHP at the end of the script.

    For more:

    PHP Manual on File Uploads

    You can also use a built-in WordPress function:

    wp_handle_upload()

  • Hmm, have you altered the default date format for this field? The default “yymmdd” should be working fine in your code sample.

    Try echoing the raw value that get_field() returns, without parsing it with strtotime(), to see what’s up with it.

  • You should run define_admin_hooks(), or at least the code that adds filters to update the ACF paths, before you run load_dependencies().

  • There may not be a built-in function in PHP to convert special characters / remove diacritics as far as I know, so implementing this might actually require searching for some functions or libraries on the net that have a complete-ish conversion table for common languages.

    At any rate, the fields should work even with special chracters.

  • On your meta_query, the key for defining the comparison type should be ‘compare’, not ‘relation’.

    WP_Meta_Query

  • I don’t think this is possible. :/

  • Add a field to the row identifying which year it belongs to, then add a condition in your loop checking this field against the current year being displayed.

    Or if you already know which rows you want based on other criteria, then you won’t need the extra field, just a conditional check at each iteration of your loop.

    If you need to know which row you’re currently on, you can use get_row_index() to obtain its index.

  • The taxonomy field does not have an array of ‘choices’, like the select field does, because the choices are loaded from the database, they are not typed out in the ACF configuration.

    You should use a database query for this:

    global $wpdb;
    $customTaxonomy = 'category';
    
    $sql = "
    	SELECT
    		te.term_id,
    		te.name
    	FROM $wpdb->terms te
    	LEFT JOIN $wpdb->term_taxonomy tt
    	ON tt.term_id = te.term_id
    	WHERE tt.taxonomy = '$customTaxonomy'
    ";
    
    $taxonomies = $wpdb->get_results( $sql, ARRAY_A );
    
    if ( $taxonomies ) {
    	echo '<select name="somename">';
    	foreach( $taxonomies as $item ) {
    		echo '<option value="' . $item['term_id'] . '">' . esc_html( $item['name'] ) . '</option>';
    	}
    	echo '</select>';
    }
  • Try formating the dates as ‘Ymd’ (with uppercase “Y”, which outputs 4 digits, as opposed to “y”, which outputs 2). This is the default format for date fields.

    Though, of course, if you have entered another format in your ACF setup for this field, then you should change accordingly. ๐Ÿ˜‰

  • You could create a page, then create an ACF group that appears only on this specific page, and then finally edit the WC checkout template to call upon these fields, using the page’s ID โ€“ get_field( ‘field_name’, $page_id ).

    If creating a page for this purpose seems inelegant, you could use this plugin that allows you to use ACF on widgets:

    Advanced Custom Fields: Widget

    In your theme’s functions.php, register a new widget area for use on your checkout, then create an ACF group for this widget, insert it in and configure it. The plugin’s documentation has some specific instructions on how to call the fields on your template, but feel free to ask if you have any doubts.

  • You could try using a plugin to add a custom permalink base URL for media files, such as this one:

    Attachment Slug

    Then target the different link types purely with CSS:

    .post-content a { /* any link or custom link */ }
    .post-content a[href*="/media_base_url/"] { /* overrides for attachment links */ }
    .post-content a[href*="/wp-content/uploads/"] { /* overrides for direct media links */ }

    The only problem is with custom links, which are not targetable by themselves. In this case, you could use some JavaScript:

    jQuery( function() {
    jQuery('.post-content a > img').parent().addClass('media-link');
    });
  • You could try appending this information to the URL of your “thanks” page:

    $post_id = (int) wp_insert_post( array(...) );
    $cat_id = (int) get_field('cat_field');
    $return_url = site_url( "/thanks/?post_id=$post_id&cat_id=$cat_id" );
  • It does, that’s how I have been doing it.

    But because it is a setup I use often on different websites, it would help if there was a built-in option that is faster to set up and takes up less column space when using inside a Repeater.

    One can dream! ๐Ÿ˜‰

  • I think it would be helpful if there was a combo box especially for links – where the user can select an internal link to a post, or enter a custom link (for external URLs, or URLs with anchors and queries).

Viewing 18 posts - 1 through 18 (of 18 total)