Support

Account

Forum Replies Created

  • Hi that’s exactly what i had to do for a project, mine was about shoes but that’s how i set it up:

    When you Publish a post if the Featured checkbox on the post is set to true the previous Featured post is set to false so you always have a single featured post.

    basically that post runs on every acf/save_post and runs before the data are saved.
    The code check if you set the true/false option for the post you are saving.
    if you did it makes a query (in my example restricted by post type) to see if there is any featured posts. If there is it will set the featured post value to false, if there isn’t it will do nothing, in both cases it will end up setting the featured value of the saved post to true.

    //First you would have to add acf/save_post action to you function.php so the action runs every time a post is saved or udpated 
    
    // run before ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_acf_save_post', 1);	
    
    function my_acf_save_post( $post_id ){
    	// vars
    	$fields = false;
     
     //here i added a if stattement so the code runs only for a defined post //type you can change "pompitup_product" or delet that if statement
    if(get_post_type( $post_id ) === "pompitup_product"){
    
    	//check if Fields have been posted
    	if( isset($_POST['fields']) ){
    
    		//store the true/false field on a variable (change 
                    //the "Field_xxx" id by yours)
    		$feature_product = $fields[field_52b2c5c9d8267];
    		
    			//check if the true/false field is true
    			if( $feature_product ){
    					
    		     //if it's set to true do a WP_query so you can get 
                        //the other post that have $feature_product set to true
    					
    	          //here you may want to change the 'post type' to 
                    //whatever your is (or to all)
    		//in the meta query you sholud use your 
                    // true/false field name as a key
    		
                   $args = array(	'post_type' => 'pompitup_product', 
    				'meta_query' => array( 
    						array( 
                                            'key' => 'produit_mis_en_avant', 
    					'value' => '1', 
    					'compare' => '==')),);
    					
                   $post_query = new WP_Query($args);
    					
    		//here we check if the query returns post (if it does 
                   //it will return featured posts
    				
                  if($post_query->have_posts() ) {
    		  while($post_query->have_posts() ) {
    		        
                            //here we get the featured post id
                         	$post_query->the_post();
    					
    			//for each posts we update the true/false 
                           //field and set it to false 
    		      
                         //again use your own field_xxx here
    		update_field('field_52b2c5c9d8267', false, get_the_ID());
    	            	  }
    		}			
    	}
    		
    
    		}//end isset($_POST['fields'])---->for post
     	}//end check if post-type== pompitup_product
    			
    	 
    }//end my_acf_save_post
    
    

    sorry about the bad indentation, I find it really hard to past code in there.

    I think there is a cleaner way to do that but that gets it working.

  • hi, I had that problem a while a go where no roles could upload images.
    in the end it was because of the “upload” folder CHMOD, it worked fine on my server but on the final host i had to tweak that with the host provider.

  • Hi,
    if you want to add custom field to the category page (or any category page) you can do so by setting the rule of the field group like that:

    [taxonomy terms] [is equal to] [Categories]

    you can set the [Categories] drop down to whatever categories you like or you can set it to [All] if you want you custom field group to display on categories AND taxonomies.

    then to display the field value on the front end have a look at
    http://www.advancedcustomfields.com/resources/functions/get_field/
    around * $post_id examples

  • Hi,
    if i understood well you may want to do a custom field type

    http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/

    to check if this is what you want have a look at the following tutorial
    http://vimeo.com/33099101

    that will give you grate control over how you field is displayed.
    but it’s maybe too heavy for what you are trying to do.

  • Hi,
    to use ACF loop with tab it works in the exact same way as you would do it without tab get_field("field_name"); it doesn’t matter what tab your field is in, the tab is just there to organize the back-end but the values of the fields are registered in the same way.

    I didn’t find any ways to do nested tabs I think it’s not possible at the moment without doing some custom code .

  • did you try the Help Desk?

  • and you want to get all the choices of the field or only the ones related to the post? to make it more clear do you want check box options displayed once on the page with all the choices or displayed on each post and restricted to the values of that post?

  • you could do an option page and use the layout field “tab” to separate you content. then you will be able to access the content of the option page as usual and it may look clearer on the back-end.

  • Hi,

    I don’t understand what should happend when the user click a checkbox, do you want to load more content with ajax? or do you want to reload the page?

  • hi,
    if you are trying to get them inside a loop (setting the specific post id you want in your arguments or getting all your posts).
    i would create an empty array before the loop then in the loop create a new array inside that array with the post id and push inside that array the meta you want in a key=>value format.

    once the loop finish you should be able to get from that array the informations you want.

    is that what you was looking for?

  • Hi,
    yeah I think you can if you put your css inline and something like that in you loop:

     
    $percent_value = get_field("numeric_value");
    echo ' <div style="height: ' . $percent_value . '%" > ... </div>';
    

    I didn’t test it but it should work.
    I think this example could be perfected including the % sign directly on the $percent_value

  • Hi, I changed a bit my taxonomy architecture.
    The website i am working on sales shoes so I made a “Brand” category with “Nike, Adidas and so on…” the shoes models “air max, air force…” are saved as a children categories of the brand they belong to.

    That way i no longer need to register_taxonomy if i want to add a new brand from my option page, i just have to insert a new term inside on the root of my “Brand” category.

    Here is how i did it:

    // run AFTER ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_acf_save_option_page', 20);	
    
    function my_acf_save_option_page( $post_id ){
        
        //getting the value of my text box
        $brand_to_add = get_field_object('field_52d6f9449e688', 'option');
         
        //Checking if the value is not empty (this also check if it exists 
        //so when i am saving a post and not the option page the 
        //wp_insert_term is not called
        if( !empty($brand_to_add['value'])){ 
            //inserting the desired value inside the "marque" category 
            //(marque = brand in french)
            wp_insert_term( $brand_to_add['value'], 'marque' );
    
        }//end if statement 
    }

    also when the option page is loaded the text field value is set to an empty string so we can add a new category

    
    // Reset new brand field
    add_filter('acf/load_field/key=field_52d6f9449e688', 'reset_new_brand');	
    
    function reset_new_brand( $field ){
        // reset choices
        $field['value'] = '';
        
        // Important: return the field
        return $field;
    }
    	
    
  • Hi, I finally managed to get it working.
    the plugin I was modifying was trying to access the field data before it was saved. that’s why it worked with an already published post entering it’s post id number but not with a new one.

    the second issue i had have been solved to, i was developing a solution to publish a post to facebook using the advanced custom fields as description value or to set the image of the facebook post, i had a scope problem with that one.

    I will try to make that last one into a plugin, i diden’t found any existing plugin that let you use ACF values to publish a post to a social network

  • Hi Elliot, I will come back to you with the full code explained a little bit better.

  • Hi Elliot, Thanks for your answer
    I did a var_dump() on the $post->ID and it outputs int(479) (or whatever the post number is) if i have a fix variable like $postID= int(479); it works.

  • I found the answer on the documentation.

    <?php $field_key = "field_52b2c7c6bc3e5";
    									$field = get_field_object($field_key);
    	 
    if( $field ){
    	echo '<select name="' . $field['key'] . '">';
    	foreach( $field['choices'] as $k => $v ){
    	echo '<option value="' . $k . '">' . $v . '</option>';
    	}
    	echo '</select>';
    } ?>
Viewing 16 posts - 26 through 41 (of 41 total)