Frage

Here's a fun one. I'm using advanced custom fields inside of a template to pull a field called Applications with the following code.

 the_field('applications');

The problem is that this won't pull the actual content without the page ID along with it, for example:

 the_field('applications','42');

where the page ID is 42.

What I would like to do is use another template tag to pull the existing page ID with something like this in place of the 42, so that it will content specific to that page:

 the_ID();

Which, in a perfect world would look like so:

 the_field('applications','the_ID();');

This is obviously ridiculous and doesn't work, but I don't know what I need to do to get this to actually work.

Thanks!

War es hilfreich?

Lösung

the_ID() will automatically echo whatever is returned, whereas get_the_ID() will return that value so that it can be stored in a variable, or passed as an argument (which is the deal in this case).

<?php the_field('applications',get_the_ID()); ?>

http://codex.wordpress.org/Function_Reference/get_the_ID

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top