Support

Account

Forum Replies Created

  • Live and learn πŸ˜‰ It’s definitely a better approach so it’s also my bad for not putting that in the original code solution

  • Or you can just switch the add_post_meta to a update_post_meta and you’ll be fine regardless πŸ™‚

  • Hi Asger,

    What are you trying to achieve? To set the featured image from within a repeaterfield?

  • Hehe I get that πŸ™‚

    Sweden is probably an interesting country to visit as an american. Lots of cultural differences (not to say the weather).

    I work for a company called tigerton so any contract work would be going through there. Should you need me you can always send me an email on [email protected]

    Have a great sunday (I think yours is about to start now)

  • Np dude, just giving some back…

    It’s a long trip from Sweden but I’ll keep that in mind πŸ˜‰

  • Hi!

    You’ve probably set the return value for the image field to be URL rather than image object. So you should not use that markup for the image. Here’s a complete version of what you’re doing:

    
    <?php 
    //check for the repeater first. We dont want to do a while loop if there are none!
    if(have_rows('favorite_cars')){
    	
    	//Loops through the repeater
    	while (have_rows('favorite_cars')) {
    		the_row();
    		
    		//fetches the post object field. Assumes this is a single value, if they can select more than one you have to do a foreach loop here like the one in the example above
    		$car_object = get_sub_field('select_car');
    	    $title = get_sub_field('car_title');
    	    $summary = get_sub_field('car_summary');
    		if($car_object){
    			//Fetch the image field from the carsandtrucks post
    			$image = get_field('main_image', $car_object->ID);
    		}
    		
    		//Echo out the image. Since you set it to only return the image URL you can only use this for src. Change the field settings to object if you want to use the version i previously posted. 
    		echo '<img src="' . $image . '" />';
    	    echo '<h2 class="favorite-car-title"><' . $title . '</div>';
    	    //Depending on what kind of field the summary is you want the <p> tag around it.. If the field is a wysiwyg field or a textarea with automatic p-tags, remove the <p> and </p> from the code. 
    	    echo '<div class="favorite-car-summary"><p>' . $summary . '</p></div>';
    		
    	}	
    	
    } 
    ?>
    
    

    Its such a small thing so don’t worry about compensation!

  • Hi!

    If I understand you correctly this should do it

    
    
    <?php 
    	//Loops through the repeater
    while (have_rows('favorite_cars')) {
    	the_row();
    	
    	//fetches the post object field. Assumes this is a single value, if they can select more than one you have to do a foreach loop here like the one in the example above
    	$car_object = get_sub_field('select_car');
    	if($car_object){
    		//Fetch the image field from the carsandtrucks post
    		$image = get_field('main_image', $car_object->ID);
    	}
    	
    	//Echo out the image with the medium size. Change this as you like!
    	echo '<img src="' . $image['sizes']['medium'] . '" width="' . $image['sizes']['medium-width'] . '" height="' . $image['sizes']['medium-height'] . '" alt="' . $image['alt'] . '" />';
    	
    	
    } 
    ?>
    
    
  • It can be called easily from a template.

    You could probably create an ajax function to call this calculation in the backend using the many hooks available for ACF (check the documentation) but it’s not the easiest solution and if you’re not sufficiently good at php/ajax/wp hooks it will be quite the challenge.

  • Or in a function in functions.php.. You can even put them in a function inside a custom plugin if you want.

    All that’s needed is that they or the call to a function in which they are calculated are placed before the echo $total.

    Easiest is indeed to put it in a page template where you want it to be shown.

  • Yes that’s correct. You will want to do the meta query on the posts ID, not the title πŸ™‚

  • I assume this has to do with the latest versions
    “Options page: Added compatibility for different language values”

    I came here to find out in what way this has been achieved so maybe I’ll get the answer here too πŸ™‚

  • It depends on what output you’ve set the field to when you created the field πŸ™‚

  • Heyo!

    Sorry for being so friggin dumb sometimes! I had created the childtheme etc. etc. but never activated it but rather used the main theme.. DUH!

    nevermind me then, carry on…

  • You need to check the documentation. How you register the options tab has changed a bit for v5, especially if you used the filter.


    @Protozoan
    have you tried checking your field so that it’s location rules are correct and resaved it?

  • You should probably use the repeater field name.. however the code above will not magically work just setting that.

    First you need to check what you’ve got in the $value variable.. I’m not sure this works but try doing a print_r($value); to see the values being saved. In the working example above the $value is just a post attachment ID. In your case with a repeater field I imagine it’s something more in line of an array or object which you’ll need to fetch the right value from.

  • @xmonkx you can just place both tabs with their respective fields in the same field group..

    It’ll give you the layout you want.

    Also in the future please start a new topic instead πŸ™‚

  • Glad you worked it out! Looks good!

    Yeah ACF is friggin awesome, saves so much time in development.

    Are you using a jquery plugin for the interactive timeline? If so could you post a link to it? Seems like a nice thing to keep for future reference πŸ™‚

  • Glad it worked out!

    Cheers

    p.s. dont forget to set this as solved

  • Great πŸ™‚

    Good luck in the project!

  • It’s possible I suppose..

    Try switching to relationship field (you can set max value to 1). The relationship field uses ajax so you should be fine even if you have thousands of products.. It’ll also give you the ability to search for a product by name which could be a bit nicer than having to search through a 5 mile long dropdown πŸ™‚

  • Use the post object field instead!

    It’ll give you the entire post object (duh) instead of just a link.

    
    <?php $postobject = get_field('post_object'); ?>
    <a href="<?php echo get_permalink($postobject->ID); ?>"><?php echo $postobject->post_title; ?></a>
    
  • The default textwidget in wordpress will not process any PHP..
    Try searching for a plugin like “text widget enhanced” or something and you’ll get a widget which can πŸ™‚

  • Hi!

    I’m not 100% sure what you’re after but assuming what you want is to avoid duplicate related posts being displayed because they’re assigned to more than one term this code should do the trick.

    It’ll create an array which it will check for each related post, if the posts slug is already in the array it’ll ignore it (and thus not display a duplicate) and if its not it’ll display the post and add it to the array.

    
    global $post;
    $taxes = array('ingredients','foodtype', 'eventtype');
    $terms = get_the_terms($post->ID, $taxes);
    $products = array();
    if( !empty($terms) ){
    	foreach($terms as $term) {
    	    if(get_field('relatedproducts', $term->taxonomy.'_'.$term->term_id )){
    			while( have_rows('relatedproducts', $term->taxonomy.'_'.$term->term_id) ) { 
    				the_row(); 
    				$post_object = get_sub_field('product');
    				if( $post_object ){ 
    				    // override $post
    				    $post = $post_object;
    				    setup_postdata( $post );
    				
    					if(!in_array($post->post_name, $products)){
    						$products[] = $post->post_name;
    						if ( has_post_thumbnail() ) { 
    							the_post_thumbnail('thumbnail',array('class'=>"img-responsive center-block"));
    						} 
    						the_title('<h4>','</h4>');
    						the_content();
    					}
    				}
    			} 
    			wp_reset_postdata(); 
    	    }
    	}
    }
    
    
  • I don’t understand how you can still have the field..

    is it the field in admin or the fields value on the front-end you wish to remove? Which is not being deleted?

    Are you sure its an ACF field?

    You can always go into your theme files and remove the output of the field there.. if it’s in single posts check single.php, if its on regular pages check page.php.

Viewing 25 posts - 801 through 825 (of 1,019 total)