1

I've run into a little bit of a snag with shortcodes. I want it to take the variable and put it in place for the text that should usually go there, but instead of working it just doesn't load it up, even though I've tested it with the echo to see if it's putting anything out and it is.

<?php 
    $artistslug = the_field('artist_cat_slug');
    echo $artistslug;    // Here for test reasons
    echo do_shortcode('[product_category category="'.$artistslug.'"]');
?>

Any help would be greatly appreciated.

2
  • the_field() is not a default WordPress function - is this from a plugin? Commented Feb 18, 2014 at 15:57
  • Sorry yeah i should clarify this is with Advanced Custom Fields plugin, my bad Commented Feb 18, 2014 at 15:58

1 Answer 1

2

Most probably, the_field() displays the value. The plugin you are using might have a corresponding function to return the value instead, for e.g. get_the_field(). Use that instead.

Edit after clarification in comments

From the documentation for the_field() (emphasis mine):

Displays the value of the specified field. (this is the same as echo get_field($field_name))

Exactly. Use get_field() instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Call to undefined function get_the_field() in /var/sites/i/inlandclothing.co.uk/public_html/wp-content/themes/inlandclothing/page-artist.php on line 27 I get this when i put it as get_the_field
@MatthewArtiman: See the spelling. It's get_field() not get_the_field().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.