Support

Account

Forum Replies Created

  • Hi @claw

    I think the easiest way for you to achieve all of these is to create your own custom fields for the title and the editor. You can then hook into the acf/save_post action hook and retrieve the values in these fields yourself and add them as the post title and post content.

    A few things to note:
    1. You have to run the remove_action before saving the post title and content (if you save them using wp_update_post) and add it back in after. Basically same thing as this explains with infinite loops except you apply it to acf/save_post: https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
    2. You’re gonna end up with two extra fields in the admin area for these title and content fields. You can remove them in the admin area using CSS or simply disable them (to stop user from being able to interact with them) using this filter: https://www.advancedcustomfields.com/resources/acfload_field/
    and setting $field['disabled'] = 1;

  • Hi @bloodlvst

    No I don’t think so.. mainly because you’re not just removing them but you’re replacing them with new values. If the new values were the same (like “=false”) for both I guess it could be done but since you’re now actively choosing to replace exact strings with new values depending on what the string is this is the way to go.

    That said I’m not an expert in hardcore PHP. But from my experience this is fine!

  • Hi @donnafefe

    You can do this to get the slug from the term id:

    
    <?php	
    $corso_id = get_field('corso', 'user_'.$current_user->ID );
    $corso_term = get_term($corso_id);
    $corso_slug = $corso_term->slug;
    
  • Hi guys,

    First off, this is not a breaking issue as you noticed. It’s a php warning so while it’s annoying you can safely use ACF as usual.

    You’ve stumbled upon a bug where ACF interprets the tab field as a repeater as well (due to the same naming as an actual repeater). The code then tries to iterate through a repeater value which isn’t there resulting in this warning.

    I’ll notify Elliot of this issue so he can patch it for the next update. It’s an easy fix πŸ™‚

    In the meantime if this still bugs you you can do what @refused9 suggests and create a new tab field with a slightly different name. After you save the field group I think you can change the name back to be the same as the repeater and it should be fine.. since the slug already exists.

  • Hi @gregorymark

    I think it’s possible this happens due to the way ACF attempts to cache meta.
    When you crop an image the previous sizes still exists as image files in the uploads folder. And when you now attempt to get the new “large” size ACF finds the already cached values for the field which contains the old image URLs for the sizes.

    Could you try playing around a bit with:
    1. Updating the field group the image field is in. see if that changes things.
    2. Remove the image from the field and re-add it.

  • Thanks. Tho I need to see some code since that does not tell me too much about it πŸ™‚

    you can post code using the “backticks”: `
    there’s also a button above the comment field.

    If there’s ALOT of it and you’re not sure what to paste you can use a service like pastebin.org

  • Ah okay cool! Glad you worked it out πŸ˜‰

    Best of luck with the project!

  • Cool πŸ™‚

    ACF Actually makes it pretty easy to create new field types if you want to give it a shot. As long as you have decent code skills beyond HTML and CSS you should be able to work it out. you can read more here: https://www.advancedcustomfields.com/resources/creating-a-new-field-type/

    Best of luck in your project!

  • Haha no worries @imaginedd
    You’ve provided a code snippet which I was too lazy to do πŸ˜‰

    It’s interesting to know that in later versions of ACF you can also provide the term object as a second parameter. I wouldn’t recommend it in this case since it’d just require an additional function call but it’s good to know when you’re doing a custom loop of get_terms() for example.

  • Hi @minburke

    I’ve seen this issue before when the values have been saved to the ACF field (to the DB) outside of ACF (not adding them through acf input) and doing so by either using update_field with the field name or using another function like update_post_meta. If you’re saving the values programmatically or in some other way you should always use update_field with the field key.

    The reason for this is because using the field_name for a meta value that does not yet exist fails to create the corresponding field key. If the field already exists tho the field key also already exists and it’s fine to use the field name.

  • just saw the images πŸ™‚ We need to know the context of this field. Where do you place it? Where are you trying to fetch it? (in single.php, index.php, a widget etc. etc.) .

  • Hi @randalthesecond

    I’m 99% sure your issue is that you attempt to get the value outside of it’s context. That means that you might be trying to fetch it outside of the loop. Or from a term/user/object that’s not a post object and thus need the second parameter.

    Just throwing in $post_id won’t help you. what @imaginedd is trying to say here is that you probably need to specify this second parameter and if it’s a field belonging to a post object you have to find the posts ID and pass it as the second parameter. For example, if you’re working outside the loop and not in a single.php or page.php you might get away with:

    
    global $post;
    if( get_field('enable_box', $post->ID) ){
      //Table with other ACF field values
    }
    

    We can’t help you further without more information about your setup tho so get those images working πŸ™‚

  • Hi @korkor

    Are you sure you’re looking in the right place?
    In the sourcecode there is a <div class="kwayy-team-group-desc"> but looking at your code template where you post the code there is not.

    That aside. When you work with something other than a post type you need to specify the second parameter as taxonomy_termid.

    So a call to the_field() where you want to fetch info from a term should look like:

    the_field('field_name', 'taxonomy_termid') where taxonomy is your tax slug and termid is the terms id.

    Check this documentation out: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

  • I’d need to see some code to figure out how you set things up πŸ™‚

  • acf_form() in itself creates a form so if you do not set it to false you will have a form within a form..

    this is the parameter 'form' => true,

    so acf_form(array('form' => false)) is minimum needed for it to work inside another form. + acf_form_header of course πŸ™‚

  • I think your request makes sense in some cases but I think it’s too small of a use-case for it to be added to ACF core.. Of course you’re free to add it as an addon tho!

  • Hi @brian1037

    Altho it might not be the prettiest, if you want to put a button somewhere using ACF you can create a “message” field and add the button to that. You can put something like

    <button type="button" class="button-secondary" id="my-ajax-trigger" data-action="myajaxaction">Trigger AJAX please</button>

    in it.

  • Hi @joelstransky

    Just throwing this out there.. why can’t you have the user set the relationship between the menu items post/page/category/whatever and any random posts? And then in your walker fetch those values from the object you added as a menu item.. The only limitation to this that I can see is if you have custom URL links in your wp nav menu.

  • Hey @walkers_inspiration

    Just a minor tweak to @imaginedd solution. You need to do a proper wrap of the if statement since you both assign a value and break the foreach loop. Otherwise the foreach will always break on first iteration.

    
    <div class="module_col">
    
    	<h3><?php the_sub_field('module_title'); ?></h3>
    
    	<?php
    	// Get List of students to check for eligibility
    	$students_list = get_sub_field('student_availability' );
    
    	// Set the default state to false, to be changed later
    	$student_authorised = false;
    
    	// Loop through students_list to check if user is allowed access
    	foreach( $students_list as $student ) :
    
    		// If user is in the list, set student_authorised to true and break out of loop
    		//(no need to loop through everybody if they're the first user)
    		if( in_array( $student_username, $student['nickname'] ) ){
    			$student_authorised = true;
    			break;
    		}
    
    	endforeach;
    
    	// If student is in the list, show download link
    	if ( $student_authorised ) : ?>
    	
    
    		<a href="<?php the_sub_field('module_download'); ?>">
    			<button class="download_btn">
    				<span><i class="fa fa-cloud-download"></i>Download Module</span>
    			</button>
    		</a>
    	
    
    	<?php 
    	// if student not in list, show authentication error
    	else : echo 'Not logged in'; endif; ?>
    
    </div>
    

    A different solution would be to fetch the ID of the current user instead and fetch the acf value unformatted. This is a bit more straight forward πŸ™‚

    
    <?php $current_user_id = get_current_user_id(); ?>
    <?php if( have_rows('course_modules') ): ?>
    	<?php while ( have_rows('course_modules') ) : the_row(); ?>
    		<div class="module_container">
    			<div class="module_col">
    				<h3><?php the_sub_field('module_title'); ?></h3>
    				<?php $allowed_user_ids = get_sub_field('student_availability', false ); ?>
    				<?php if ( in_array( $current_user_id, $allowed_user_ids ) ): ?>
    					<a href="<?php the_sub_field('module_download'); ?>">
    						<button class="download_btn"><span><i class="fa fa-cloud-download"></i>Download Module</span></button>
    					</a>
    				<?php else : ?>
    					<p><?php _e('You\'re not allowed to download this module'); ?></p>
    				<?php endif; ?>
    			</div>
    			<div class="module_col">
    				<?php the_sub_field('module_details'); ?>
    			</div>
    		</div>
    	<?php endwhile; ?>
    <?php endif; ?>
    
  • Hi @venkatesham

    So to build on @felipeost answer with a real functional example using WordPress functionality. You should be able to paste this into your themes functions.php and just change the ID numbers (1 and 2) to the correct ones for your pages.

    
    function my_custom_redirect(){
    		
    	global $post;
    	$model_name = get_field( 'model_name', $post->ID );
    	
    	switch ($model_name) {
    	    case 'iphone':
    			$redirect = get_permalink(1); // Change 1 to the ID of your iphone page
    			wp_redirect($redirect);
    			exit();
    			break;
    		case 'samsung':
    	        $redirect = get_permalink(2); // Change 2 to the ID of your samsung page
    			wp_redirect($redirect);
    			exit();
    			break;
    	}
    	
    }
    add_action( 'template_redirect', 'my_custom_redirect' );
    
  • @shokry055

    My guess is that @izstubbz failed to notice this in the example:

    
    // 3. Hide ACF field group menu item
    add_filter(β€˜acf/settings/show_admin’, β€˜__return_false’);
    

    That would hide ACF from wp-admin so even if it’s correctly integrated he/she wouldn’t see it.

  • Hi @sireagroup

    How are you using acf_form()? Do you have it inside another form and set the form parameter to false so it’ll be included in that form instead? Do you have the acf_form_header() function above get_header()?

  • Hi @noma

    In what way is WPML messing things up for you? ACF is supposed to be compatible with WPML. Even the options pages with a little bit of custom tweaking: https://www.advancedcustomfields.com/resources/multilingual-custom-fields/

    You’re not using WPMLs latest RC/Beta of their new version? Because I don’t think elliot has had the chance to look at that yet.

  • Hi @steviec

    Great to hear that you solved it and thank you for posting your solution here for others to find πŸ™‚

  • No worries!

    Yeah for you as a front end developer in WordPress knowing about the ways you can optimize the wp_query is really important. I’m always finding myself using at the very least one of the parameters to remove a query. I also regularly refactor older queries to give them a performance boost!

Viewing 25 posts - 76 through 100 (of 1,019 total)