Support

Account

Forum Replies Created

  • Hi @pixelcrash,

    That sounds like pretty much what I’m looking for. Would you mind sharing your hook code that generates the css file by any chance? That’s the bit I’ve been getting stuck on.

  • Hi John,

    It’s a radio field. I set the return format to be value…and have now decided I need to get the label! 🙄

  • Solution

    I should’ve known there would be a built in solution for this. First time I’ve used a filter on the relationship field results, but this is so, so useful.

    For anyone else who comes across this, here’s a helpful tutorial just to bring it all home: https://philkurth.com.au/tips/customise-the-post-titles-in-acf-relationship-field/

    Here’s how I adapted it to show me a bit more info about the returned results and still make it reasonably legible:

      add_filter( 'acf/fields/relationship/result', function ( $title, WP_Post $post, $field_arr ) {
    
        $posted_at = get_post_time( 'U', false, $post->ID );
        $now = current_time( 'timestamp' );
        $diff = human_time_diff( $posted_at, $now );
        $permalink = get_permalink( $post->ID );
    
        return '<strong>' . $title . '</strong><br>' . $permalink . sprintf( ' (%s ago)', $diff );
      }, 10, 3 );

    This outputs the permalink of each page, along with how long ago it was published. Combined with the small featured image this should be enough to recognise any page.

    Just one more reason to love this plugin.

  • Anybody have any ideas? This is becoming a real problem for me as it means I have to just guess when selecting pages and then check the front end and hope for the best. Even if it could return the page title and the URL that would be immensely helpful.

  • Hi John,

    Thank you for your considered feedback. It’s always good to hear others’ opinions as we all know it’s very easy to get tunnel vision and end up down rabbit holes in the world of dev.

    I absolutely agree that page load times are critical. My ultimate goal was to generate these stylesheets and then concatenate them into a single one to reduce http requests. However, inline or stylesheet blocks would clearly still be quicker.

    My worry about placing stye tags throughout the document (not just in the head) would be flashes of unstyled content before the DOM has fully loaded. Though I guess it depends what those style tags are targeting as to whether it’s worth the tradeoff.

    I think for now I might have to settle on header style blocks as this seems a happy medium and I think you’re right, me in 6 months will look back and probably hate now now for trying to be too clever!

    Thanks John

  • After a bit more experimenting it seems to be something to do with the “ACF Content Analysis for Yoast SEO” plugin. It seems to load the admin-ajax.php on every keystroke. After upgrading to the latest WordPress the console errors went away on our site but the admin-ajax file was still being continually polled. There is now an issue about it on the plugin forum: https://wordpress.org/support/topic/admin-ajax-php-loaded-on-every-keystroke/

  • Thanks James. As ever with ACF, it’s simply a case of thinking about the issue a slightly different way and you can nearly always find a solution.

  • Perfect, thank you!

  • Hi Elliot,

    I’ve fixed it. Interchange does indeed use ajax to switch out files and I think that’s why the acf values weren’t being loaded – because, as you correctly pointed out, wp didn’t know which post to pull them from.

    I added the page ID to the repeater code and it worked:

    <?php
    require($_SERVER['DOCUMENT_ROOT'].'/pwp/wp-load.php');
    ?>
    
    <div class="phone_email_holder">
    
    <p>LARGE TEMPLATE</p>
    
    	<?php if( have_rows('phone_numbers', 7) ): ?>
    			<?php while( have_rows('phone_numbers', 7) ): the_row(); ?>
     			<div class="contact_field_wrapper row">
    	        	<div class="phone_email_label info_label">
    	        		<?php echo get_sub_field('number_label', 7) ?>:
    	        	</div> 
    	        	<div class="phone_email_value">
    	        		<?php echo get_sub_field('tel_number', 7) ?>
    	        	</div>
    		    </div>
    		<?php endwhile; ?>
    	<?php endif; ?>
    	
    </div>

    However, it does have to include the wp-load file to work.

    Thanks for your help on this. I only recently discovered ACF and it’s bloody amazing. Good work!

    Thanks,
    Xav

  • Hi Elliot,

    Thanks for getting back to me.

    The template is a custom include file. I have a custom template for my contact page and within that I’m calling the contact_details_small.php or contact_details_default.php that has the acf fields in. When the fields are placed directly in the contact template they work fine, but when I move them to the the include files I get nothing.

    I’m beginning to think maybe I’m just using the acf code wrong as the include files are definitely being read because plain html is being output. I simplified the code above so as to make it easier to understand. The full code in the include file is below:

    <?php
    require($_SERVER['DOCUMENT_ROOT'].'/pwp/wp-load.php');
    ?>
    
    <div class="phone_email_holder">
    
    <p>LARGE TEMPLATE</p>
    
    	<?php if( have_rows('phone_numbers') ): ?>
    			<?php while( have_rows('phone_numbers') ): the_row(); ?>
     			<div class="contact_field_wrapper row">
    	        	<div class="phone_email_label info_label"><?php echo get_sub_field('number_label') ?>:</div> 
    	        	<div class="phone_email_value"><?php echo get_sub_field('tel_number') ?></div>
    		    </div>
    		<?php endwhile; ?>
    	<?php endif; ?>
    	<?php if( have_rows('email_addresses') ): ?>
    			<?php while( have_rows('email_addresses') ): the_row(); ?>
     			<div class="contact_field_wrapper row">
    	        	<div class="phone_email_label info_label"><?php echo get_sub_field('email_label') ?>:</div> 
    	        	<div class="phone_email_value"><a class="" href="mailto:<?php echo get_sub_field('email_address'); ?>"><?php echo get_sub_field('email_address') ?></a></div>
    		    </div>
    		<?php endwhile; ?>
    	<?php endif; ?>
    </div>

    The “LARGE TEMPLATE” bit is being output from the above code. Just not the rest. All I’m doing is removing links from telephone numbers for the desktop version of the site and adding them back in for mobile versions.

    Thanks for looking into this.

Viewing 13 posts - 1 through 13 (of 13 total)