Support

Account

Forum Replies Created

  • do you have a very large amount of data to save at once?

  • Hi,
    you can do it like this:

    $currentDate = date('Ymd');	
    $args = array(
        'numberposts' => -1,
        'meta_key' => 'date',
        'orderby' => 'meta_value_num',
        'order' => 'ASC',
    	'meta_query' => array( 
             array( 
    	        'key'		=> 'date',
    	        'compare'	=> '>=',
    	        'value'		=> $currentDate,
                ),
    	 )
    	);

    this would return all the posts where the “date” field is equal to the current date or later. (you would need to change the “date” on my code to your “event_date” field name and add other arguments you may want to have like “cat”=> ‘2’ the save format of your date field should be set to yymmdd

  • Hi, I was doing it like this, (I was using the update_field functions but with get_field it should work ass well)

    // run AFTER ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    
    function my_acf_save_post( $post_id ){
    
    $var = get_field('field_name', $post_id );
    
    }	

    that should get you the saved values after they are saved, if you want to modify them before they are saved you should use :

    
    // run before ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_acf_save_post', 1);

    and then follow the doc here:
    http://www.advancedcustomfields.com/resources/actions/acfsave_post/

  • Hi, you could pass the post id as a param to your function and then use get_field with the post id

  • Hi,

    i tried something like that

    var $ = jQuery;

    $(document).on('click', '.acf-flexible-content .acf-fc-remove',  function(e)
    {
    	
    if(confirm("you are about to delet an element!")){
    						
    				}else{
    					 e.stopImmediatePropagation();
                                   return false
    					}		
    
    });

    but the click event of the field is still triggered and the row gets deleted.

    any hints on that?

  • Hi,
    i am not sure but i think you can access the parent name inside your repeater_load_value(); with $field['name']; maybe store that in a variable and pass it as a param to the sub_field_load_value()

  • Hi,
    you could use the following plugin
    http://www.advancedcustomfields.com/add-ons/taxonomy-field/
    to display on ACF a radio button with your 3 catégories, the post will get attached to the selectedi categorie, that way your code will still work.

  • Hi, I am trying to do something like that as well, here is what i got so far:

    lets say you have a custom field with the name “field_1” and one with the name “field_2” and you want the field to return the $value as an array:

    make sure that you custom field html got some input with name="field_1" and name="field_2" in the function update_value(); of your custom field put something like:

     if( $value ) {
    
         //an array to hold your values
         $all_values = array();
         
         $all_values['field_1'] = $value['field_1'];
         $all_values['field_2'] = $value['field_2'];
    
         return $all_values;
    }

    the value of your field is now an array like:

    `[“value”]=>
    array(2) {
    [“field_1”]=>
    string(4) “one ”
    [“field_2”]=>
    string(3) “two”
    }

  • Hi,
    If you want to show only the posts that have a true/false checkbox checked (the checkbox that trigger the two other field on your backend).
    you should restrict to these posts directly on your query

    'meta_query' => array(
        'post_type' => 'areas-of-focus',
        array(
         'key' => 'is_a_featured_area_of_focus',
         'value' => '1',
         'compare' => '=='
        )
     )

    something like that should return only the posts that have the is_a_featured_area_of_focus field set to true.

    so you can get rid of if( get_field('is_a_featured_area_of_focus') ) : and other stuff related to checking if this field is checked on the loop and just take care of the layout.

    let me know how that goes

  • Hi,
    A closing parenthesis was missing in my example

    $args = array(
        'numberposts' => -1,
        'post_type' => 'OGs',
        'orderby'   => 'meta_value', 
        'order' => 'ASC',
        'meta_key' => 'city',
        'meta_query' => array( 
          array( 
            'key' => 'state', 
            'value' => 'texas', 
             ),
         )
    );

    I tested my code in a fresh install of WP, it outputs all the posts with a state value of texas (text input custom field named state) and sort by city alphabetical (with another text input custom field named city).

    the only difference in my test is that i didn’t test with the same post_type, let me know if you still having issues.

  • Does acf/save_post runs when posts are pending?
    if it doesn’t you could check if your field_534dc7420db07 has a value and update it with $value only if it doesn’t. if acf/save_post runs before the values are stored in the database an “updated” post will already have a value for that field and wont get updated.

    would that work?

  • let me know if you still having issues

  • Hi,

    so what you want is get posts by state name and then when outputting them sort them by city.

    maybe you could try that, instead of having 2

    set up your $args like that:

    $args = array(
             'numberposts' => -1,
    	 'post_type' => 'OGs',
             'orderby'   => 'meta_value', 
             'order' => 'DESC',
    	 'meta_key' => 'city',
    );

    this code above should return all the OGs posts ordered by city however the states part is missing i don’t know if you can add it as below.

    $args = array(
             'numberposts' => -1,
    	 'post_type' => 'OGs',
             'orderby'   => 'meta_value', 
             'order' => 'DESC',
    	 'meta_key' => 'city',
             'meta_query' => array( 
                             array( 
                             'key' => 'state', 
                             'value' => 'Texas', 
                             ),
    );

    I diden’t test that but looks like the ‘orderby’ => ‘meta_value’ is a good start.

    let me know how it goes

  • Hi,
    I had a look at the transition_post_status action on the codec, looks like it’s “not intended for use by plugin and theme developers”.

    if you $value is a static value I think what you want is pretty straight forward with ACF.

    // run AFTER ACF saves the $_POST['fields'] data
    // here we run the acf/save_post AFTER the data are saved and we update the field to your $value
    
    add_action('acf/save_post', 'my_acf_save_post', 20);	
     
    function my_acf_save_post( $post_id ){
      
        $value = "12345";
        update_field('field_534dc7420db07', $new_tax, $post_id);
    }
    

    That way you ensure that the $value stays always the same, it can be on newly published posts or on post that goes from pending to published, as soon as the post is saves the field_534dc7420db07 gets your value after it was saved.

    you should leave the acf.php as it was and shouldn’t comment anything on that part it will end up breaking things.

    then if you want to make more complicated stuff you can check if the post is published or pending or any other stuff using it’s id that is stored in $post_id

  • Hi,
    I have an idea it’s not realy clean code, could use some improvement but it should work.

    // check if the repeater field has rows of data
    if( have_rows('repeater_field_name') ):
     
     	// loop through the rows of data
        $i = 0;
        while ( have_rows('repeater_field_name') ) : the_row();
        $get_value = get_sub_field('sub_field_name');
        
        $i++;
        if($i == 1 || $i == 4 || $i == 7 ){
            echo '<ul>'
         }
            // display a sub field value
            echo '<li>' . $get_value . '</li>'
        if($i == 3 || $i == 6 || $i == 9 ){
            echo '</ul>'
         } 
        endwhile;
     
    else :
     
        // no rows found
     
    endif;

    well that is not realy great if you want to change the number of content on each blocs but it could be perfecter for exemple if you add a custom field on you repeater (a true/false for example that set the oppening <ul> and another one that sets the closing </ul>) you could look for those on the while loop and output an oppening or closing ul before or after an element

  • Hi,
    I had a similare issue where when i substracted 1 to the post id it was working and with the current post ID it wasen’t.
    In my case it was caused by the fact that at the point of updating the field value, the values wasen’t saved yet.

    I am not sure if i understand what you are trying to achive but it looks like you want to register a value to the posts that wasen’t published ang got changed to publish.

    If you are trying to do that for new post and want the function to run only when post is created you could use

    // run before ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_acf_save_post', 1);

    inside your my_acf_save_post you could check if field_534dc7420db07 is set.
    If it is it will mean you are juste updating the post if it dosen’t it means it’s a new post and you can update the field value.

    If you are trying to run your function when a post pass from private to published
    have you tried to call private_to_published action?

    hope it helps

  • is the following line missing in your code?

    while ( have_rows('your_repeater_row') ) : the_row();

    so you may want to try like that to get the sub field:

    <?php while ( have_rows('your_repeater_row') ) : the_row(); 
               
     $attachment_id = get_sub_field('photo');
     $custom_feature = wp_get_attachment_image_src( $attachment_id, "slide-thumb" );
    ?>
    
     <img src="<?php echo $custom_feature[0]; ?>" />	
    	   
    <?php endwhile; ?>
    
  • Hi,
    I think I may have an idea on that one, you could create a category called
    “Recipes” in that category you would have te following child categories “RecipeCAT1, RecipeCAT2, RecipeCAT3” and so on…

    when you create a post you asign “Recipes” and “RecipeCAT1” as categories.

    then you could get all the “RecipeCAT” in an array with get_terms
    and inside a foreach loop put a wp_query that will get you the post from each RecipeCAT and display them one after the other.

  • great, you code is clearer than mine as it uses “$fieldId” and my field_id are hard coded, i will use that on the future 🙂

  • I had a typo on my example code as i had to delete some necessary stuff.

    you should add $fields = $_POST['fields'];
    after if( isset($_POST['fields']) ){

    and before $featuredArticle = $fields[$fieldId];

    let me know

  • Hi,

    you should store your other field in a variable as well,

    Then before rendering your blockquote your run an if statement that check if the testimonial is available, if it’s not it skips the blockquote part

    someting like:

    
    $testimonial = get_field('testimonial');
    
    if($testimonial && !empty($testimonial)){
    
    // build your quote blockquote with the if img... 
    
    }

    this case doesn’t test for the name if you want the testimonial AND the name you should write:

    
    $testimonial = get_field('testimonial');
    $name = get_field('name);
    
    if($testimonial && !empty($testimonial) && $name && !empty($name)){
    
    // build your quote block with the if img... 
    
    }

    I haven’t tested this code but an if statement before your <blokquote> building is what you need, you can find more info about the if “or”, “and” conditions here if you want to set up something more complex.

    http://www.php.net/manual/en/language.operators.logical.php

  • Hi,
    in your $args you can’t add multiple ‘meta_key’ => ‘…’, ‘meta_value’=>’…’ on the same level.

    you will want to replace your meta_key and meta_value entry by a multiple array:

    
    $args = array(
    'some_args' => 'some value,
    'meta_query' => array( 
                       array( 
                         'key' => 'state', 
                         'value' => 'Texas', 
                       ),
                       array(
                          'Key' => 'city',
                          'value' => 'Houston'
                       ),
    'some_other_args' => 'some_value'
    );
    

    This should get you the state of Texas and the city of Houston with all the other args you have defined.

    you may want to use variable on your states and city value.

    I haven’t tested this code so let me know how it goes.

  • Hi,

    I had some issues with that to i actually set 3 different sizes
    “custom-thumb”, “feature-img” and “main-img” infunction.php but unlike what you said I use a single field which generate all 3 sizes.

    I set the return value to image ID

    and I am able to get the images in the front end like that:

    
    $attachment_id = get_field('you_field_name');
    
    //in the $custom_thumb var i get the custom_thumb infos replace "product-thumb with the name of your custom size you set in function.php
     
    $custom_thumb = wp_get_attachment_image_src( $attachment_id,"product-thumb" );
    
    //then you are able to output the following values from the $custom_thumb var:
    // the url: $custom_thumb[0];
    // the width: $custom_thumb[1];
    // the height: $custom_thumb[2];   
    
    //use these variable as you like on your html
    
    <img src="<?php echo $custom_feature[0]; ?>" />
    
    //or
    <img src="<?php echo $custom_thumb[0]; ?>" width="<?php echo $custom_thumb[1]; ?>" height="<?php echo $custom_thumb[2]; ?>" />
    
    //you can do the same with any other custom sizes or with the original sizes
    //just change the last argument "product-thumb" to what you need on that line (the $attachement_id should be declared as seen above).
    $your_var = wp_get_attachment_image_src( $attachment_id,"your-custom-size" );
    
    //then $your_var shoud have the data you want.
    
    

    you can still have different fields to upload your images and declare 3 times
    $attachment_id_1 = get_field(‘you_field_thumb’);
    $attachment_id_2 = get_field(‘you_field_feature’);
    $attachment_id_3 = get_field(‘you_field_custom’);

    but that’s only necessary if the images are different if it’s the same image the 3 sizes gets generated when you upload the first time.

    then to control the crop you can add that little plugin

    http://wordpress.org/plugins/manual-image-crop/

    it does a good job.

Viewing 25 posts - 1 through 25 (of 41 total)