Support

Account

Forum Replies Created

  • I faced the same issue while adding the field group via PHP using the current_user action hook and generating the field value dynamically, based on the post_id.

    By its nature the AJAX call does not recognize the current_user action hook (and others). Switching to admin_init did the trick for me. The field group will then remain visible when assigning a taxonomy term.

  • you’re welcome! Hope it will be usefull for you (:

  • These functions are just placeholders. You can replace them by any code you would like to run when saving the specific option page.

    In my case I clear three transients when I save my option page.

  • Of course. I have five different option pages.
    Create a function for each option page with the the condition above and replace the string “acf-options-adverts” with the slug of the attached option page (you may have a look in the url-bar of each page).

    In your case for example I could imagine the code to look like this:

    if (strpos($screen->id, "acf-options-product") == true) {…
    if (strpos($screen->id, "acf-options-service") == true) {…
    if (strpos($screen->id, "acf-options-theme-option") == true) {…
  • Just for your information the get_current_screen function solved the problem in my case. Check my post for an example how to use it:

    http://support.advancedcustomfields.com/forums/topic/acfsave_post-for-specific-options-page/

  • I found a solution after reading this post: http://support.advancedcustomfields.com/forums/topic/when-using-save_post-action-how-do-you-identify-which-options-page/

    While using WP get_current_screen()-function you can check if the ID in the output-array contains the slug of your specific option page.
    http://codex.wordpress.org/Function_Reference/get_current_screen

    For example you have an options page called “adverts” and want run the function mentioned above when you save this specific option page:

    function clear_advert_main_transient() {
    	$screen = get_current_screen();
    	if (strpos($screen->id, "acf-options-adverts") == true) {
    		delete_transient('advert_main_transient1');
    		delete_transient('advert_main_transient2');
    		delete_transient('advert_main_transient3');
    	}
    }
    add_action('acf/save_post', 'clear_advert_main_transient', 20);

    Now WP Transients make even more fun and will save you tons of queries if you have complex acf-fields and loops! 🙂

  • Ok that makes sense. I tried to use get_post_meta() at the beginning of my single.php but had some difficulties with deserializing my gallery-field… But isn‘t this field only queried once?
    When I use the get_post_meta here would have to loop each attachment-ID with wp_get_attachment_image_src to get the sources for each image, which would go along with additional queries and would not improve the performance, right?

    <?php $post_data = get_post_meta($post->ID); 
    $galerie_neu = $post_data['galerie_neu'][0]; 
    if ($galerie_neu) {
    ($galerie_neu) { 
    $galerie_neu = unserialize($galerie_neu);
    foreach ($galerie as $galerie_item) {
    $galerie_id = $galerie_item['bild'];
    $thumb = "galerie";
    $full = "large";
    $image = wp_get_attachment_image_src( $galerie_id, $thumb );
    $fancybox = wp_get_attachment_image_src( $galerie_id, $full );
    ?>…

    I guess the main amount of queries is generated through my option-fields (about 400 out of 600). I checked my database and found about 100 unused old fields which are not listed in the backend anymore – would deleting them enhance the performance?
    Caching the option-fields would – in my optionion – solve my performance problem as every single page makes up to 100% use of all these fields. So I would have to manually change all option-field-entries in the DB to autoload = yes? Would that be a conclift issue with the JSON-feature?

    I will mark your post as the solution – because it helps in generally but in my eyes does not help in my special case.

    Thanks again for your help!

  • I see… So the main problem I think is, that most of the queries occour by the amount of sub-fields in repeater fields I have on option pages.

    If I would create a pseudo option page which would be in fact a custom post type with only one post the repeater would perform better?

  • Thanks for your advice but I have already done this.
    Currently I use W3 Total Cache with its page-, db- and browser-caching function.

    I was more like searching for a method to bundle different queries (e.g. repeater data).

  • 1. That’s right! I almost forgot about this….

    Here’s a link to a zip-file with two screenshots and the full php-code. I commented the area where the magic should happen:

    https://www.dropbox.com/s/e5dc0ttbxzc9roz/ACF_Problem.zip

    I hope you get through the code.. it contains many conditions :/

    Thanks a lot for your effort!

  • Hi @elliot

    sorry for that. so i’m going to explain it to you 🙂

    This is the code i took from your documentation (example 4):

    <?php 
     
    // args
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'event',
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key' => 'location',
    			'value' => '%Melbourne%',
    			'compare' => 'LIKE'
    		),
    		array(
    			'key' => 'location',
    			'value' => '%Sydney%',
    			'compare' => 'LIKE'
    		)
    	)
    );
     
    // get results
    $the_query = new WP_Query( $args );
     
    // The Loop
    ?>
    <?php if( $the_query->have_posts() ): ?>
    <ul>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    	</ul>
    <?php endif; ?>
     
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

    And the following code is an extract of my entire liveticker code (http://derschlag-handball.de/liveticker). My liveticker works perfect so far, but it takes too much time to fill in all the fields when e.g. somebody makes a goal, etc.

    So what I did was to create another repeater field for each team, where I can write in all players with their numbers. When the match is running I only have to type in the number of the player and in my liveticker the name of the player will be picked from the new created repeater field.

    And there’s my problem. The liveticker repeater field works perfectly (where I always have to type in the players name and number). I also created a second (and third) repeater field for the team-list (number and name of each player). But my code with the modified query of your example (above) does not work:

    <?php
    $number = get_sub_field(‘liveticker_nummer’);
    $name = array(
    ‘numberposts’ => 1,
    ‘post_type’ => ‘liveticker’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘nummer_heim’,
    ‘value’ => $number,
    )
    )
    );
    $name_query = new WP_Query( $name );?>
    
    …
    
    <?php if(get_sub_field(‘ereignis’) == “Tor”) : ?>
    durch <?php if( $name_query->have_posts() ) : while ( $name_query->have_posts() ) : $name_query->the_post(); ?>
    <?php the_field(‘name_heim’);?><?php endwhile; endif; ?> (<?php the_sub_field(‘liveticker_nummer’);?>)</p>
    
    …

    get_sub_field(‘liveticker_nummer’) = get’s the number of the player I tiped in the liveticker repeater field (for each event, like e.g goal)

    ‘nummer_heim’ = the field of my team-list, where the number of the player is listed

    ‘value’ => $number = my goal is that the code uses the number in the liveticker repeater field to query the row of the team-list where also his name is located

    the_field(‘name_heim’) = the name which belongs to $number in the team-list

    I hope you understand what I mean and can help me with that! thanks 🙂

  • I tried but it didn’t work. Maybe you could change the code the way I used the repeater fields?

    <?php $attachment_id = get_field('liveticker_logo_heim', 'option');
                                      $size = 'medium'; // (thumbnail, medium, large, full or custom size)
                                      echo wp_get_attachment_image( $attachment_id, $size );
                                ?>
                                </div>
                                <div class="logo_gast">
                                    <?php $attachment_id = get_field('liveticker_logo_gast', 'option');
                                          $size = 'medium'; // (thumbnail, medium, large, full or custom size)
                                          echo wp_get_attachment_image( $attachment_id, $size );
                                    ?>
                                </div>
                                <div class="clear"></div>
                                <div class="ergebnis">
                                <div class="tore_heim"><?php the_field( "liveticker_tore_heim", 'option' );?></div>
                                <div class="ergebnis_zeichen">:</div>
                                <div class="tore_gast"><?php the_field( "liveticker_tore_gast", 'option' );?></div>
                                </div>
                                <div class="clear"></div>
                            </div>
                        </div>
                        <div class="liveticker_box">
    					<?php if(get_field('spielverlauf', 'option')): ?>
      						<?php while(has_sub_field('spielverlauf', 'option')): ?>
                            <div class="liveticker_wrapper">
    						<ul>
                                	<li class="liveticker_ergebnis">
                                    	<?php if(get_sub_field('minute')) : ?>
                                        <p><?php the_sub_field('minute');?>. Minute<br/>
                                        <?php else : ?><br/>
                                        <?php endif ;?>
                                        <?php if(get_sub_field('liveticker_tore_heim')) : ?>
                                        <?php the_sub_field('liveticker_tore_heim');?> : <?php the_sub_field('liveticker_tore_gast');?></p>
                                        <?php else : ?>
                                        <?php endif ;?>
Viewing 12 posts - 1 through 12 (of 12 total)