Jump to content

Get Value from Field


Fran
 Share

Recommended Posts

Silly question maybe, but I'm new to PW.

How can I retrieve the value of a custom field?

I'm trying for the label:

<?php echo $fields->get("caracteristicas_superficie")->label; ?>

And it's working just fine, but:

<?php echo $fields->get("caracteristicas_superficie")->value; ?>

doesn't work

Thanks very much. :)

Link to comment
Share on other sites

Labels are field-specific, i.e. generally they apply everywhere the field is used. Values on the other hand are always page-specific, i.e. each page has a separate value for each field.

This is why you should be asking for the value of this field from a specific page. For current page you can use $page, and for other pages you can, for an example, do this: $pages->get('/page/url/').

<?php echo $page->caracteristicas_superficie; ?>
<?php echo $pages->get('/page/url/')->caracteristicas_superficie; ?>
Or:
<?php echo $page->get('caracteristicas_superficie'); ?>
<?php echo $pages->get('/page/url/')->get('caracteristicas_superficie'); ?>
I would suggest taking a proper look at https://processwire.com/api/ before stumbling any further. The basic stuff is all explained there :)
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...