airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.32k stars 110 forks source link

Endpoint to get a field's raw value #121

Open hirasso opened 7 years ago

hirasso commented 7 years ago

Hi there, love your plugin!!!

One question: is it possible to retrieve a field's raw value? I need to get a WYSIWYG-Field, without the shortcodes being converted already – so basically without any filters being applied to it.

airesvsg commented 7 years ago

Hi @hirasso, :smile: Please, use the function remove_all_shortcodes. https://codex.wordpress.org/Function_Reference/remove_all_shortcodes

Thanks

hirasso commented 7 years ago

hi @airesvsg, thanks for your quick response! remove_all_shortcodes is no option though, since the theme needs them installed, and I am getting the data from another url.

ACF's get_field function supports a third parameter, if you set this to false, no filters are being applied. It would be amazing if you could incorporate this functionality. A quick example:

// my_custom_field_name is a wysiwyg field
get_field('my_custom_field_name', $post_id, false);

....results in a field being fetched from the database without wpautop, the_content filters or any shortcodes applied to it.

eddiewebb commented 7 years ago

I had the same need, but for HTML encoding.

Wordpress returns a "rendered" and "raw" for each field. Is there a way I can use one of the filters to get the "raw" equivalent?

Wordpress core values:

"title": {
        "raw": "It's Gneiss",
        "rendered": "It’s Gneiss"
    },

ACF field:

    "acf": {
        "description": "<p>Classic pun for geologists and optimists alike. Don&#8217;t confuse these mineral types.</p>\n",

I'd like it without the added <p> and &#8217