Support

Account

Home Forums General Issues Return a custom field in functions.php

Solving

Return a custom field in functions.php

  • I’m sure this is something simple that I just don’t know how to do. I’m using a plugin to autocomplete my search field and I’m customizing the link that returns using the code below.

    add_filter( ‘search_autocomplete_modify_url’, ‘saModifyURL’, 10, 2 );

    function saModifyURL( $link, $object ) {
    $newLink = ‘http://website.com/?Click=<?php the_field(“id_number”); ?>’;
    return $newLink;
    }

    My issue is I need to return the custom field “id_number” that is associated with the result into the link. I found the documentation on doing this on it’s own but is it possible to mix them together to return that in my result?

  • You will need to get know what post or where you’re getting the field from and supply the value in the second of…. and you’ll also need to use get_field() which I just noticed. the_field() echoes the value so first try

    
    add_filter( 'search_autocomplete_modify_url', 'saModifyURL', 10, 2 );
    
    function saModifyURL( $link, $object ) {
      $newLink = 'http://website.com/?Click=<?php get_field("id_number"); ?>';
      return $newLink;
    }
    

    if that does not work then figure out how you’re going to supply the post id

    
    get_field("id_number", $post_id);
    

    side note, use back ticks to include code, or click the code link at the top of the editor.

  • Thanks for your help. I ended up going a different route that didn’t require hotlinking.

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

The topic ‘Return a custom field in functions.php’ is closed to new replies.