Support

Account

Home Forums General Issues option_home filter and Acf Page Links for CPT Archives

Solved

option_home filter and Acf Page Links for CPT Archives

  • I use this code to change urls. It is working with links to pages. But it is not working with links to archives.

    The links are coming from an ACF-Page-Link-Field

    How can I fire the filter also for archive-links?

    add_filter( ‘option_home’, ‘custom_site_url’);

    function custom_site_url( $url )
    {
    if( is_admin() ){
    return $url;
    }

    $mainurl = get_site_url();
    $flag =””;

    if(which_language()==”en”){
    $flag = “/en”;
    }
    $mainurl_with_flag = $mainurl.$flag;
    $url = str_replace ($mainurl, $mainurl_with_flag, $url);

    return $url;
    }

  • Maybe the ACF-Page-Link delivers a flat url? Right?

    If so, how can I select a cpt via an acf-field? I started a new thread:
    https://support.advancedcustomfields.com/forums/topic/it-is-possible-to-select-a-custom-post-type-via-acf/

  • ACF set the URL when the page is selected and stores one of 2 things, one is a post ID when selecting a post and the other is the URL of an archive page.

    I do not know if your filter will work in the case of a post ID, in this case ACF calls get_permalink() for the post.

    In the second case ACF does not do anything, it just returns the value stored in the DB. In this case you would need to use an acf/format_value filter to alter the returned URL.

    This is the only field available in ACF that I know of that will allow selecting archive pages. Beyond this you are looking at either building a custom field or building several custom filters for an existing field type,

  • thank you very much!
    At the end I am using a simple textfield to save the title of a custom post type.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.