Support

Account

Home Forums General Issues Page Link issue with own field function

Solved

Page Link issue with own field function

  • Hi,

    I use my own functions for the acf field output like this:

    function ACF_GSF( $field, $post_id = null ) {
    	
    	if ( ! is_acf() ) { return false; }
    	
    	if ( get_sub_field( $field, $post_id ) ) { 
    		return get_sub_field( $field, $post_id );
    	} else { 
    		return false; 
    	}
    	
    }

    This works in all my cases. But if I use the “Page Link” field, the URL result is not the right one.

    With my own function ACF_GSF('button_page'), I get a wrong URL like an IP http://0.0.6.24/

    With the original function get_sub_field('button_page') everything is fine. I get the URL of the selected page.

    Can you help me to find the reason of this issue? 🙂

  • Hi @wootimes

    Please keep in mind that you don’t need to pass the post ID to the get_sub_field() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_sub_field/.

    So you should do it like this:

    function ACF_GSF( $field, $post_id = null ) {
    	
    	if ( ! is_acf() ) { return false; }
    	
    	if ( get_sub_field( $field ) ) { 
    		return get_sub_field( $field );
    	} else { 
    		return false; 
    	}
    	
    }

    I hope this helps 🙂

  • @acf-support oh, thanks! That’s it 🙂

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

The topic ‘Page Link issue with own field function’ is closed to new replies.