Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi @goodwebsites

    The only way to do this is to hook into the save function of the gallery field (before ACF saves the new value) and compare the previous and new values.

    From there you can delete the attachment post records you need to.

    Use the above search to find more info on the acf/update_value filter which you can use to hook into the gallery field save function.

    The rest should be straight forward but will require time and debugging skills.

    Good luck

  • Hi @Athen

    Yes, ACF is compatible with WPML.

    You can translate pages independently to have different custom field values.

    Does this solve the question or is there something specific you want to know?

  • Okay, this works. But, holy schnikes, that’s a lot of work for one little list!

    <label>Presenter: </label>
    <?php
    #----------------- GET THE DISTINCT LIST OF SERIALIZED PRESENTERS FROM PRESENTATIONS																		
    $presenter_id_array = array();
    $presenter_data = $wpdb->get_col( 
    "SELECT DISTINCT wp_postmeta.meta_value FROM wp_posts 
    INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
    WHERE 1=1 AND wp_posts.post_type = 'presentations' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_key = 'presenters' ) 
    GROUP BY wp_posts.ID ");		
        
    #----------------- LOOP THROUGH THAT LIST										
    foreach ($presenter_data as $presenter_data_item)
    {
        #----------------- DO A QUERY TO GET A SPECIFIC PRESENTATION POST
        $args = array(
            'post_type'	=> 'presentations',
            'posts_per_page'     => -1,					
            'post_status' => 'publish',											
            'meta_query' => array(
              array(
                'key' => 'presenter',
                'value' => $presenter_data_item,
                'compare' => '=',
              )
            )																							
        );																	                                       
        
        $custom_loop = new WP_Query($args);	
        #echo "<br /><br >". $custom_loop->request; 	
        
        #----------------- GET THAT PRESENTATION'S DATA
        if( $custom_loop->have_posts() ):						
        
            while( $custom_loop->have_posts() ): $custom_loop->the_post(); 
            
                #----------------- GET THE PRESENTER RELATIONSHIP FIELD DATA
                $posts = get_field('presenter');
                 
                if( $posts ): 
                    foreach( $posts as $post_object): 
                        
                        #----------------- FINALLY, GET THAT STAFF ID OUT OF THE RELATIONSHIP FIELD!!!!
                        #----------------- ADD IT TO MY LIST OF STAFF IDS
                        array_push($presenter_id_array,$post_object->ID);
                    endforeach; 
                endif;																																																								
            endwhile;        
        endif;																										
    }									
                                        
    #----------------- NOW, DO A QUERY FOR A SUBSET OF STAFF WHO ARE PRESENTERS
    $args = array(
        'post_type'	=> 'staff-members',
        'posts_per_page'     => -1,					
        'post_status' => 'publish',
        'order' => 'ASC',
        'orderby' => 'title',
        'post__in' => $presenter_id_array												
    );																	                                       
    
    $custom_loop = new WP_Query($args);	
    #echo "<br /><br >". $custom_loop->request; 	                                       												
    
    ?><select name="search_presenter">
        <option value="">-</option>
            <?php if( $custom_loop->have_posts() ):						
            
                while( $custom_loop->have_posts() ): $custom_loop->the_post(); 
                    
                    ?><option value="<?php get_the_id(); ?>"><?php the_title(); ?></option><?php
                endwhile;        
            endif;
            
            // Reset Query
            wp_reset_postdata(); ?>
    </select>                                    
    
  • Also, to clarify, the value I’m getting back for the presenter in that $presenter_data query is a serialized item like this:

    a:1{i:0;s:2:"71";}

    71 is the ID I’m trying to get. I realize I could use some PHP to manipulate this, just seems like there must be a better way.

  • Thanks for your quick reply. There’s probably something I’m not understanding about $term_id. I have a regular WP post category of “stories-by-state” which has subcategories of each state (alabama, alaska, etc.). I don’t think the fact that I’m retrieving subcategory info has any effect on the outcome.

    Given your instruction, I would have something like the folowing:

    the_field('test_field', 'alabama_' . $term_id);

    or

    the_field('test_field', 'alabama_16');

    where 16 is the the number I get from the ur:l /wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=16&post_type=post

    Neither worked and I”m not 100% sure how to pull $term_id.

  • So, later on, I realized that this is not the right way to go about it. Really what I want is a subset of a CPT called “staff.” I want to get the staff who are presenters on my CPT called “presentations.”

    Therefore, it seems like I should do a query on “staff” but just get the ones whose ID is used in the presentations. Right?

    $args = array(
    	'post_type'	=> 'staff-members',
    	'posts_per_page'     => -1,					
    	'post_status' => 'publish',
    	'order' => 'ASC',
    	'orderby' => 'title',
    	'post__in' => $presenter_id_list												
    );

    However, this starts getting way more complicated than it seems like it should… in order to get the $presentation_id_list data, I can get the distinct list of presenters here:

    $presenter_data = $wpdb->get_col( 
    "SELECT DISTINCT wp_postmeta.meta_value FROM wp_posts 
    INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
    WHERE 1=1 AND wp_posts.post_type = 'presentations' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_key = 'presenters' ) 
    GROUP BY wp_posts.ID ");

    But that gives me an array of the serialized “presenter” relationship field. How do I get at the ID in that relationship field??? This seems like it is getting way more complicated than it needs to be. Am I missing something?

    Thanks!

  • I’ve also been looking for a way to get the key from a name. The best solution I’ve come up with is adding a function which does a switch/case on the field name and applies a filter to return the key. However, it does require that you manually code a case/return/break for each field (probably not practical if you’ve got more than a few dozen fields).

    Code here: https://gist.github.com/wells5609/5971010

  • @relish27

    Change the “orderby” arg to ‘orderby’ => ‘meta_value’ and then specify ‘meta_key’ => ‘presenter’ (rather than ‘meta_value’ => ‘presenter’). This will order the query results by the meta_value of ‘presenter’.

    It sounds like you’re trying to also query posts with a specific ‘presenter’ value. If so, add to the $args array:

    
    'meta_query' => array(
      array(
        'key' => 'presenter',
        'value' => '"' . $presenter_value . '"',
        'compare' => 'LIKE',
      )
    )
    
  • Okay, so I see there is this — http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/

    But I wish there was an example of it in use, not just in the functions.php. I’m still not sure how to actually use it in my case.

  • BTW, I realise this may well be a question for the creator of the custom post type plugin, feel free to send me that way if you think this is not in your remit.

    I’m asking it here because I wonder if there’s something I can do with the custom field to get the category ID out.

  • Maybe it is worth more information, but I understand that “live” triggers are able to be used on DOM elements populated after the page has loaded. Likewise, I have set up some working code in order to close this created popup when the newly created ACF form is submitted.

    Also here is a helpful example for other users viewing this forum to submit their acf form with jQuery – works very nicely.

    $( "#acf-ajax-form" ).live( "submit", function( event ) {
        event.preventDefault();
    
        $(this).find('input[type=submit]').attr("disabled", true).val("Processing...");
    
        var formData = $(this).serialize();
        var formUrl = formData.return;
    
        $.post(formUrl, formData, function(response) {
            // Close the popup container
            $('#my-popup-container').foundation('reveal', 'close' );
    
            // Clear the HTML
            $('#my-popup-container').html('');
        });
    });

    Is there a way in which we might perform the jQuery trigger that you suggested above (acf/setup_fields) to mimic the “live” event?

  • 1 – For all of the custom fields that I control the naming of, I prefixed the key with an underscore (i.e. “_my_custom_field”). This prevents them from being displayed in WordPress’ custom fields drop-down list.

    2 – For the custom fields that ACF automatically generates (i.e. when using tabs, ACF uses the “field_51” prefix on the site that I’m working on), I wrote some PHP:

    if(!function_exists(‘kc_hide_meta_keys_start’)){
    function kc_hide_meta_keys_start( $num ){
    add_filter( ‘query’, ‘kc_hide_meta_keys_filter’ );
    return $num;
    }
    add_filter( ‘postmeta_form_limit’, ‘kc_hide_meta_keys_start’ );
    }
    if(!function_exists(‘kc_hide_meta_keys_filter’)){
    function kc_hide_meta_keys_filter( $query ){
    remove_filter( current_filter(), __FUNCTION__ );
    // Match keys beginning with field_51
    $where = “WHERE meta_key NOT LIKE(‘field_51%’);
    $find = “GROUP BY”;
    $query = str_replace( $find, “$where\n$find”, $query );
    return $query;
    }
    }

  • I have activated the qTranslate plugin, without this plugin ACF work normal.

  • save_post() works fine in 4.1.8, and doesn’t create any errors. Here’s XDebug Context for ACF 4.1.8 , breakpoint at $f = apply_filters('acf/load_field', false, $k ); in acf.php:save_post( $post_id )

    Inside the loop, 1st iteration (single date and time picker field):

    
    $f = array[18]
    	$f['name'] = (string) dato
    	$f['class'] = (string) date_time_picker
    	$f['time_format'] = (string) H:mm
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[2]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    		$f['conditional_logic']['status'] = (int) 0
    	$f['show_week_number'] = (string) false
    	$f['value'] = <string>
    	$f['required'] = (int) 0
    	$f['type'] = (string) date_time_picker
    	$f['id'] = (string) acf-field-dato
    	$f['key'] = (string) field_51d520b7091da
    	$f['label'] = (string) dato
    	$f['picker'] = (string) slider
    	$f['show_date'] = (string) true
    	$f['order_no'] = (int) 0
    	$f['instructions'] = <string>
    	$f['save_as_timestamp'] = (string) true
    	$f['date_format'] = (string) m/d/y
    $v = (string) 7/11/13 7:00
    $post_id = (int) 6640
    $k = (string) field_51d520b7091da
    $this = Acf[1]
    	$this->settings = array[5]
    		$this->settings['path'] = (string) /Users/per/Sites/dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['dir'] = (string) http://dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['upgrade_version'] = (string) 3.4.1
    		$this->settings['hook'] = (string) advanced-custom-fields/acf.php
    		$this->settings['version'] = (string) 4.1.8
    

    Second iteration, date and timepicker field inside a repeater field

    
    $f = array[16]
    	$f['name'] = (string) repeat
    	$f['class'] = (string) repeater
    	$f['field_group'] = (int) 6583
    	$f['conditional_logic'] = array[3]
    		$f['conditional_logic']['allorany'] = (string) all
    		$f['conditional_logic']['rules'] = array[1]
    			$f['conditional_logic']['rules'][0] = array[3]
    				$f['conditional_logic']['rules'][0]['operator'] = (string) ==
    				$f['conditional_logic']['rules'][0]['field'] = (string) null
    				$f['conditional_logic']['rules'][0]['value'] = <string>
    		$f['conditional_logic']['status'] = (int) 0
    	$f['layout'] = (string) table
    	$f['row_min'] = (int) 0
    	$f['button_label'] = (string) Add Row
    	$f['sub_fields'] = array[1]
    		$f['sub_fields'][0] = array[18]
    			$f['sub_fields'][0]['label'] = (string) dato2
    			$f['sub_fields'][0]['name'] = (string) dato2
    			$f['sub_fields'][0]['value'] = <string>
    			$f['sub_fields'][0]['key'] = (string) field_51da7b24dbf9a
    			$f['sub_fields'][0]['instructions'] = <string>
    			$f['sub_fields'][0]['save_as_timestamp'] = (string) true
    			$f['sub_fields'][0]['column_width'] = <string>
    			$f['sub_fields'][0]['order_no'] = (int) 0
    			$f['sub_fields'][0]['id'] = (string) acf-field-dato2
    			$f['sub_fields'][0]['picker'] = (string) slider
    			$f['sub_fields'][0]['class'] = (string) date_time_picker
    			$f['sub_fields'][0]['time_format'] = (string) h:mm tt
    			$f['sub_fields'][0]['type'] = (string) date_time_picker
    			$f['sub_fields'][0]['show_week_number'] = (string) false
    			$f['sub_fields'][0]['show_date'] = (string) true
    			$f['sub_fields'][0]['required'] = (int) 0
    			$f['sub_fields'][0]['date_format'] = (string) m/d/y
    			$f['sub_fields'][0]['conditional_logic'] = array[3]
    				$f['sub_fields'][0]['conditional_logic']['status'] = (int) 0
    				$f['sub_fields'][0]['conditional_logic']['rules'] = (int) 0
    				$f['sub_fields'][0]['conditional_logic']['allorany'] = (string) all
    	$f['required'] = (int) 0
    	$f['type'] = (string) repeater
    	$f['id'] = (string) acf-field-repeat
    	$f['key'] = (string) field_51da7b12dbf99
    	$f['label'] = (string) repeat
    	$f['order_no'] = (int) 1
    	$f['instructions'] = <string>
    	$f['row_limit'] = <string>
    $v = array[2]
    	$v['acfcloneindex'] = array[1]
    		$v['acfcloneindex']['field_51da7b24dbf9a'] = <string>
    	$v[1373458984969] = array[1]
    		$v[1373458984969]['field_51da7b24dbf9a'] = (string) 7/12/13 12:00 am
    $post_id = (int) 6640
    $k = (string) field_51da7b12dbf99
    $this = Acf[1]
    	$this->settings = array[5]
    		$this->settings['path'] = (string) /Users/per/Sites/dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['dir'] = (string) http://dev.local/wp-content/plugins/advanced-custom-fields/
    		$this->settings['upgrade_version'] = (string) 3.4.1
    		$this->settings['hook'] = (string) advanced-custom-fields/acf.php
    		$this->settings['version'] = (string) 4.1.8
    
    

    But I guess this is not really the issue. As said previously, the content exist in post meta but it’s not displayed/populated to the custom field.

    When I open a post, where (in ACF) is data read from post meta (ie, where should I set my breakpoints)?

  • Ah yes, we’re using v3.5 – I’ll go ahead and try to upgrade to see if that does the trick. Thanks Elliot!

  • I ended up using this code that works great:

    
    $attachment_id = get_sub_field('gallery_image');
    $size_thumb = "gallery-img"; // (thumbnail, medium, large, full or custom size)
    $size_gallery = "full"; // (thumbnail, medium, large, full or custom size)
    	 
    $image_thumb = wp_get_attachment_image_src( $attachment_id, $size_thumb );
    $image_gallery = wp_get_attachment_image_src( $attachment_id, $size_gallery );
    	// url = $image[0];
    	// width = $image[1];
    	// height = $image[2]; ?>
    	
    <div class="gallery-img">	
     <img alt="Dance Avenue" src="<?php echo $image_thumb[0]; ?>" />
      <div class="enlarge-img">
       <?php
        echo '<a class="fancybox" rel="group-'.get_the_ID().'" href="';
        echo $image_gallery[0];
        echo '">View Images</a>';
       ?>
    </div>
    
  • Thanks to you both. Maybe the problem lies in qTranslate? Others seem to be having the same problem with the 2 plugins. The link below was a solution for many (so it may help someone, not me unfortunately).

    http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=4&t=3436

    I managed a workaround by hiding the core editor and merging a couple of posts together (not ideal but it’s fine!).

  • Hi Elliot,
    First off i’d like to thank you for providing this wonderful plugin. It has done wonders for me so far.

    I found a dirty hack of using the ‘pre-save-post’ filter function to get the attachment ID and programmatically change the post parent. The function is:

    function attachment_change_parent($aid,$pid) {
    	global $wpdb;
    	$query = "UPDATE {$wpdb->prefix}posts
    		SET post_parent = $pid
    		WHERE ID = $aid";
    	return ($wpdb->query( $wpdb->prepare($query) )) ? true : false;
    } 

    It works so far but it is not the best option. I will eagerly await your update on this.

    Otherwise thanks again. Keep up the good hard work sir!

  • No JS errors on page. Success AJAX callback function does indeed run. (Is there any way to print JS errors from the AJAX request url?)

    Matched ID in JS acf/setup_fileds trigger to the $options[‘form_attributes’][‘id’] from when setting up form.

    Ran code after HTML was returned as well as attempted a 5000 milisecond timeout function to double check. (Not really necessary since the HTMl is returned before the AJAX success callback function is run).

    If you are familiar with Zurb Foundation, I am using this JS to return the HTML within the container DOM:

    LINK

    $(".reveal-popup-button").click(function(event) {
        event.preventDefault();
    
        $("#my-popup-container").foundation("reveal", "open", {
            url: ajaxurl,
            action: "my_popup_ajax",
            type: "POST",
            success: function(data) {
                $(document).trigger("acf/setup_fields", $("#acf-ajax-form"));
            },
            error: function() {
            }
        });
    });

    And here is my WP AJAX action:

    function my_popup_ajax_callback() {
        echo "<div id="my-popup-content">";
            $args = array(
                "post_title" => "Draft",
                "post_status" => "draft",
            );
    
            $id = wp_insert_post( $args );
    
            $html = my_popup_build_acf_form( $id, 12 );
    
            echo $html;
    
        echo "</div>";
        die();
    }
    add_action( "wp_ajax_my_popup_ajax", "my_popup_ajax_callback" );

    And the function that returns the form’s HTML:

    function my_popup_build_acf_form( $id, $fieldgroup ) {
        $options = array(
            "post_id" => $id,
            "field_groups" => array( $fieldgroup ),
            "form_attributes" => array(
                "id" => "acf-ajax-form"
            ),
            "return" => add_query_arg( "updated", "true", get_permalink( $id ) ),
            "html_field_open" => "<div>",
            "html_field_close" => "</div>",
            "html_before_fields" => "",
            "html_after_fields" => "",
            "submit_value" => "Submit",
            "updated_message" => "Post updated.",
        );
    
        ob_start();
        acf_form( $options );
        return ob_get_clean();
    }
  • Aah, I see!

    Thanks for the info. I’ll fix this up ASAP

  • Hi @kurdt_the_goat

    Both of these outputs are possible with PHP. Please see below for the first example:

    
    <?php 
     
    /*
    *  Loop through a Flexible Content field and display it's content with different views for different layouts
    */
    
    $counters = array();
     
    while(has_sub_field("content")): 
    
    	
    	// update counter
    	$layout = get_row_layout();
    	
    	if( !isset( $counters[ $layout ] ) )
    	{
    		// initialize counter
    		$counters[ $layout ] = 1;
    	}
    	else
    	{
    		// increase existing counter
    		$counters[ $layout ]++
    	}
    
    	?>
     	
     	<p><?php echo $layout; ?> instance #<?php echo $counters[ $layout ]; ?></p>
     	
    	<?php if(get_row_layout() == "paragraph"): // layout: Content ?>
     
    		<div>
    			<?php the_sub_field("content"); ?>
    		</div>
     
    	<?php elseif(get_row_layout() == "file"): // layout: File ?>
     
    		<div>
    			<a href="<?php the_sub_field("file"); ?>" ><?php the_sub_field("name"); ?></a>
    		</div>
     
    	<?php elseif(get_row_layout() == "featured_posts"): // layout: Featured Posts ?>
     
    		<div>
    			<h2><?php the_sub_field("title"); ?></h2>
    			<?php the_sub_field("content"); ?>
     
    			<?php if(get_sub_field("posts")): ?>
    				<ul>
    				<?php foreach(get_sub_field("posts") as $p): ?>
    					<li><a href="<?php echo get_permalink($p->ID); ?>"><?php echo get_the_title($p->ID); ?></a></li>
    				<?php endforeach; ?>
    				</ul>
    			<?php endif; ?>
     
    		</div>
     
    	<?php endif; ?>
     
    <?php endwhile; ?>
    
  • Thank you for your response! That was my suspicion as well, however it seems that your suggestion is not working. I tried these two snippets within the success function of the AJAX request:

    $(document).trigger('acf/setup_fields', $('#id-of-container'));

    AND

    $(document).trigger('acf/setup_fields', $('#id-of-acf-form'));

    Neither of those worked… I will be honest and say that I would be considered a newbie at jQuery, so perhaps you could offer any more guidance? Of course we all thank you for the helpful support in these forums… it is definitely gracious and helpful.

  • Hi @realnsleo

    Thanks for the question. The WP uploader uses a JS variable stored in acf.o.post_id to set the ‘attached to’ data of an image.

    I’m not sure you would be able to edit this to the new post_id as the new post_id has not yet been created…

    I will soon be releasing a new field for ACF which is a basic file input field and will allow you to bypass this issue completely.

    Until then, I’m not sure what the solution is…

  • Hi @xranerx

    A simple counter can be used to limit the fields. I have taken the liberty of neatening your code and adding in a limiter of 4 rows:

    
    <?php if(get_field('show_dates', 'option')):
    	
    	$i = 0;
    	
    	?>
    	<ul>
    		<?php while( has_sub_field('show_dates', 'option') ): 
    			
    			$i++;
    			
    			if( $i > 4 )
    			{
    				break;
    			}
    			
    			?>
    			<li><a href="<?php site_url(); ?>/show-dates"><?php the_sub_field('show_date_table_city');?></a></li>				 
    		<?php endwhile; ?>
    	</ul>	 
    <?php else: ?>
    	<p>Show dates to be announced soon.</p>
    <?php endif; ?>
    

    Please continue to practice your PHP and write clean code that does not have mixed styles.

    Good luck

  • Hi @coalesce

    This should not be publishing the changes. Can you post which version of ACF you are using?

    I believe this was an issue with pre v4, but v4 did fix this.

Viewing 25 results - 21,251 through 21,275 (of 21,364 total)