Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • I wasn’t setting the ID into the my_post array.

    I’ve added that in and it works now for both new and updated posts. Weird how it updated for existing items but now new items.

    	if ( get_post_type( $post_id ) == 'equipment' ) {
    
    		$my_post = array();
    		$my_post['ID'] = $post_id;
    		$my_post['post_title'] = get_field( 'name', $post_id );
    		
    		wp_update_post( $my_post );
    
    	}
  • Hi Elliot,

    I’ve updated accordingly, but the problem remains. I’ve made a video of how it behaves and copied the code I’m using below. It all seems pretty kosher. Could it be something to do with the post_id not being ready for new posts?

    http://www.youtube.com/watch?v=tzkWP_SBRjU

    function my_post_title_updater( $post_id ) {
    
    	if ( get_post_type( $post_id ) == 'testimonial' ) {
    
    		$my_post = array();
    		$my_post['post_title'] = get_field( 'name', $post_id ) . ' - "' . substr(get_field( 'testimonial', $post_id ), 0, 30) . '..."';
    		
    		wp_update_post( $my_post );
    
    	}
    
    	if ( get_post_type( $post_id ) == 'equipment' ) {
    
    		$my_post = array();
    		$my_post['post_title'] = get_field( 'name', $post_id );
    		
    		wp_update_post( $my_post );
    
    	}
    
    }
     
    // run after ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_post_title_updater', 20);

    Thanks,
    Andy.

  • Hi @qstudio

    If this week goes well, ACF5 should be out in beta by friday!

    Thanks
    E

  • Hi @caju

    New topics are only allowed to be added from Monday to Friday. In the future, please do not jump onto another thread and post your question. Instead, wait until the support forum hours are open.

    As for your question, the file field does not return the filesize data. I’ll add this to the to-do, but for now, you can load it like so:

    
    $attachment = get_field(’tile_package’);
    $filesize = size_format(filesize( get_attached_file( $attachment['ID'] ) ));
    

    Thanks
    E

  • Hi,

    This appears to do the job. Expanding on the theme of testimonials, it will update the actual WP post title based on two ACF fields, ‘name’ and ‘testimonial’. It will set the title as follows…

    NAME – “First 20 characters…”

    function my_post_title_updater( $post_id ) {
    
    	if ( get_post_type() == 'testimonial' ) {
    
    		$my_post = array();
    		$my_post['post_title'] = get_field( 'name', $post_id ) . ' - "' . substr(get_field( 'testimonial', $post_id ), 0, 30) . '..."';
    		
    		// Update the post into the database
    		wp_update_post( $my_post );
    
    	}
    
    }
     
    // run after ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'my_post_title_updater', 20);

    You could sharpen up the shortening of the testimonial, but everything I need to solve the challenge I had, seems to be achievable with this code.

    For prosperity, I’m using the ‘Custom Post Type UI‘ plugin to register the custom post types.

    Thanks for everyones help and input.

  • Hi Elliot,

    Thanks for getting back to me.

    Your suggestion sounds about right – but I don’t understand why on some pages the field types are loading normally – I have Query Monitor plugin installed and this informs me of slow or heavy queries – and it does not complain at all.

    I have put in place a temporary fix ( manually re-creating the selects from the data ) – this is good enough for a few weeks – when is V5 due out – I’d be happy to wait?

    Cheers 🙂

    Ray

  • 1. don’t understand
    2. understand
    3. yes
    4. in attachment
    5. yes
    6. understand

    Its complicated, I have a second thought, its easily define title of a post by using 'post_title' => $_POST["fields"]['field_52e6af7f6f4b8']
    As like this, can I define field for custom taxonomy “rent”, 'rent' => $_POST["fields"]['field_52e6afd36f4bc'] or for post Tags 'post_tag' => $_POST["fields"]['field_52ee3572071cd']
    where field_52e6afd36f4bc or field_52ee3572071cd is custom text field.
    If second thought is possible, first is dismissed.

    Thanks for holiday replay.

  • Hi @jwight1234

    The easiest option is to use the repeater field to ‘repeat’ your custom field type. This involves no code updates to work.

    If you want just 1 field on the page, which can save multiple values, then you need to add in multiple input elements.

    Currently, you should have an input that has a name attribute of $field[‘name’].
    <input name="<?php echo $field['name'] ?>" value="something" />

    To save multiple values as an array, you can change this to:

    
    <input name="<?php echo $field['name'] ?>[]" value="val 1" />
    <input name="<?php echo $field['name'] ?>[]" value="val 2" />
    

    Adding in the extra [] to the name, allows you to save values as an array!

    Thanks
    E

  • Hi @hastingsgull

    Why not:

    
    <?php if(get_field('worksheet_link')): ?>
    	<a href="<?php the_field('worksheet_link'); ?>">Go to Worksheet</a>
    <?php endif; ?>
    

    Thanks
    E

  • Hi @shatilarefin

    I have a few questions regarindg your code:
    1. The code should be wrapped in a filter for acf/pre_save_post
    2. This is a filter for the acf_form function
    3. Are you using the acf_form function?
    4. If so, what $options are you using in the acf_form function?
    5. Have you debugged your code?
    6. There is an issue with your code: $_POST['field_52e6afd36f4bc'] should be $_POST['fields']['field_52e6afd36f4bc']

    Thanks
    E

  • Hi @qstudio

    It is possible that you have a large amount of posts in the DB, and because the current post_object field is not efficient, it is failing to query all the pages form the DB.

    This has been fixed in ACF5 (soon to be released), but it may also be another issue entirely.

    You said that the issue only happens on the live site, not local? This points to the issue being a DB load problem.

    If you want, I can log into your site, and if you give me access to edit plugins, I can do some debugging in the post_object field to find the issue?

    Thanks
    E

  • Hi @lowercase

    If you are using the post_object to select an ‘artist’ for each ‘release’, then you can simply query the posts to find all releases from 1 artist by following this tutorial:
    http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/

    Thanks
    E

  • Hi @SQD

    Thanks for the question. You are quite right, the data is still intact in your DB and it is possible to change the field type from repeater to flexible content.

    Both field types save the sub field data in the same way, the only difference is the way they save their own reference data. By this, I mean how many rows are saved.

    The repeater field will simply save a number like so: 3
    This means that there are 3 rows of data available, and the repeater field will load them in.

    The flexible content field does not save just a number, instead it save’s an array of ‘layout’ names like so: array('content', 'images', 'download')
    This means that there are 3 rows of data available, and the flexible content can load the appropriate ‘layout’ and the data.

    So, all you need to do is edit your DB (wp_postmeta table) where the meta_key is your repeater field name. The value will be a number, and you will need to change it to a SERIALIZED array containing the correct number of layout names.

    Hope that helps.

    Thanks
    E

  • Seems it could well be ACF:-

    event.returnValue is deprecated. Please use the standard event.preventDefault() instead. load-scripts.php?c=1&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jq…:4
    body.scrollLeft is deprecated in strict mode. Please use ‘documentElement.scrollLeft’ if in strict mode and ‘body.scrollLeft’ only if in quirks mode. load-scripts.php?c=1&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jq…:304
    body.scrollTop is deprecated in strict mode. Please use ‘documentElement.scrollTop’ if in strict mode and ‘body.scrollTop’ only if in quirks mode. load-scripts.php?c=1&load%5B%5D=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jq…:304
    Uncaught ReferenceError: acf is not defined

    The last error in bold is flagged red.

    Thanks
    Glenn

  • Plus 1 on this request. It wasn’t clear to me from the docs that the fields added via PHP wouldn’t show. I took it to mean that would only be the case if I specifically disabled the UI. Would be really helpful to have the option to show them.

  • Issue: Field Group location rule is being stored to database but is NOT being shown as selected when viewing the Field Group.

    Steps to reproduce:
    1) Go to Custom Fields menu
    2) Select Add New Field Group from top of page. Title: Gallery Details
    3) Create fields (XML at bottom of this post)
    4) Select Location Rule = Show this field group if Post Type is equal to gallery.
    5) Publish Field Group.
    6) Go to Gallery Post Type edit screen and the ACF form is there.
    7) Go back to Field Group and Edit Gallery Details.
    8) The Location Rule defaults back to Post Type = post.
    9) If I update anything in the field group and do not also re-change the location rule back to Post Type = gallery, the ACF form will be moved from gallery CPT to post.

    I *believe* the issue is related to my initial choice to use _ in my field names (gallery_photo, gallery_event, gallery_photographer) causing the location group to return to default.

  • This is what I did. Thanks.

    //Upload la photo dans le dossier
    require_once(ABSPATH.’wp-admin/includes/file.php’);
    $uploadedfile = $_FILES[‘photo’];
    $movefile = wp_handle_upload($uploadedfile, array(‘test_form’ => false));

    //On sauvegarde la photo dans le média library
    if ($movefile) {
    $wp_upload_dir = wp_upload_dir();
    $attachment = array(
    ‘guid’ => $wp_upload_dir[‘url’].’/’.basename($movefile[‘file’]),
    ‘post_mime_type’ => $movefile[‘type’],
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($movefile[‘file’])),
    ‘post_content’ => ”,
    ‘post_status’ => ‘inherit’
    );
    $attach_id = wp_insert_attachment($attachment, $movefile[‘file’]);

    update_field(‘photo’, $attach_id, ‘user_’.$current_user->ID);
    }

  • Thanks for the response @elliot. Is it something that could be requested as a paid add-on or to the core?

  • My apologies for the confusion.

    My code prints out the loop that I want, however, it is not sorted by the date field that I specified. I just need my loo[p to list items in chronological order based on the date field that is specified in the query.

    'meta_key' => 'date_received',
    'orderby' => 'meta_value_num',
  • Hi, thank you for this,

    It works much as the second and third options do already – that is – as long as it’s not wrapped in a hyperlink it shows only on those introductions that have a worksheet. Once I wrap the if statement with href:

    <a href="<?php if(get_field('worksheet_link')){the_field('worksheet_link');} ?>">Go to Worksheet</a>

    …it appears on all the introductions again.

    Any other ideas?

  • Sorry elliot still your work with a novice here… still working on my PHP knowledge. Couldn’t get the print_r function to work for me either 🙁

    Thanks again for your help, the plugins you have developed are great and it’s change the way I work with and understand wordpress. Cheers

    Here is my code for the page

    <?php
    /*
    Template Name: Project Template
    */
    ?>
    <?php get_template_part('templates/content', 'page'); ?>-->
    <?php get_template_part('templates/page', 'header'); ?>
     <div class="wrap container" role="document">
        <div class="content row">
    	<?php
    		
    	$args = array(
    		'post_type' => 'projects',
    			'order' => 'ASC'
    	);
    	
    	$the_apppage = new WP_Query( $args );	
    
    	?>
    <div  class="row">
    <?php if ( have_posts() ) : while ( $the_apppage->have_posts() ) : $the_apppage->the_post(); ?>
    	<div class="col-md-4">	
    	<i class="fa fa-arrow-circle-o-right"></i>			
    		<article class="project-item web-design image">
    			<a class="imageover" href="<?php the_permalink(); ?>">			
    			<!-- Gallery Test Code Here -->	
    			<?php $images = get_field('gallery'); ?> 
    			<h1><img src="<?php echo $images[0]["url"]["thumbnail"]; ?>" ></h1>	
    			<!-- Gallery Test Code Here end -->			
    				<img class="img-responsive project-thumb" src="<?php the_field('gallery_feature_image');?>" alt="<?php the_title(); ?>"><!--Project thumb -->		
    				<div class="details">				
    					<h3 class="project-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3><!--Project Title -->
    					<small><?php the_excerpt(); ?></small><!--Project Categories -->					
    				</div>
    			</a>			
    		</article>						
    	</div>			
    		<?php endwhile; else: ?>		
    		<p>There are no posts or pages here</p>
    	<?php endif; ?>						
    </div>
    </div>
    
  • I add bellow code to the theme function.php

    $post = array(
            'post_status'  => 'publish',
            'post_title'  => $_POST["fields"]['field_52e6af7f6f4b8'] ,
    	'post_content' => $_POST["fields"]['field_52e6af906f4b9'],
            'post_type'  => 'post' 
         );  
     
        // insert the post
        $post_id = wp_insert_post( $post ); 
        
        update_field('field_52e6afd36f4bc', $_POST['field_52e6afd36f4bc'], $post_id);
    
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
     
        // return the new ID
        return $post_id;
    }

    where “field_52e6afd36f4bc” is the field key of custom taxonomy “rent”. I don’t understand what is update_field()’s $value for frontend new post, where user insert a value, not like the example- $value=”some string”.

    And where I put update_field(), into function.php or templete.php.

  • Right. I’m confused. Of cause this is the wrong place for that question, sorry.

  • Hi @elliot!

    It’s exactly what @Bienfeo and @unkulunkulu have already described. But let me try to be a bit more precise (and correct) on this issue:

    In case a file with the name “wp-content/object-cache.php” exists (which is provided by the quite common “Memcached” plugin “http://wordpress.org/extend/plugins/memcached/&#8221;, version 2.0.2), then updating of ACF values will fail (not creation though!).

    I was wondering if you could emit a simple pointer to this issue at the top of the ACF management section in the backend (“wp-admin/edit.php?post_type=acf”, which integrates the “create_options” method from each field type). That place would be where you get stuck in case you have an “wp-content/object-cache.php” installed and you could simply tell people:

    If you are unable to update ACF values, please try removing or renaming the file “wp-content/object-cache.php” from your installation.

    Cheers

    Günther

  • Hi @Spathon,

    Please tell me if this:
    http://support.advancedcustomfields.com/forums/topic/slow-page-load-w-page-links/

    answers your question. If not, just reply back here.

    Cheers

Viewing 25 results - 18,901 through 18,925 (of 21,345 total)