Home › Forums › Pro Support › Custom Fields
Tagged: acf
- This topic has 43 replies, 11 voices, and was last updated 2 years, 10 months ago by
elvin.
-
AuthorPosts
-
July 25, 2016 at 1:00 am #205
David
ParticipantWill the plugin support custom fields in a future version?
(As referred to in ACF or Term fields as referred to in the Toolset plugin, or sometimes called meta-fields)
TIA, DaveJuly 25, 2016 at 10:27 am #220Tom
KeymasterHi David,
It’s already possible with some PHP.
For example:
add_action( 'wpsp_before_content', function( $settings ) { if ( 123 === $settings['list_id'] ) { $meta = get_post_meta( get_the_ID(), '_your_custom_meta_key', true ); if ( $meta ) { echo $meta; } } } );
These are the available hooks we can “hook” content into:
wpsp_before_wrapper wpsp_before_header wpsp_before_title wpsp_after_title wpsp_before_content wpsp_after_content wpsp_after_wrapper
More will be added as time goes on 🙂
Let me know if you need more info.
July 25, 2016 at 6:12 pm #261David
ParticipantThanks, I’ll have a play when I have a moment…
DaveJuly 25, 2016 at 6:18 pm #262Tom
KeymasterNo problem 🙂
September 1, 2017 at 2:33 am #2566Thierry
ParticipantHi Tom,
there is the new for this ?
please, can you explain exactly how i do for display a custom field with ACF in WPSP.
Thank you
September 1, 2017 at 10:03 pm #2576Tom
KeymasterYep, the above is definitely the best way to do this still.
With that code, just update the custom field name, and use whatever hook is necessary 🙂
September 2, 2017 at 6:02 am #2577Thierry
Participantyes of course, great 🙂
April 3, 2018 at 11:23 pm #4089Ben
ParticipantHi Tom,
What is the best way to get multiple custom fields? Do I need to get each & echo one individually?
I am trying to combine the example above with the one in this post but am struggling a bit.
I have multiple custom fields I want to append to WPSP, eg: event_date, event_description, venue_title etc.
I have a Custom Post Type (using CPT UI) for Events, then using ACF for the additional custom fields.
Thanks,
BenApril 4, 2018 at 9:45 pm #4103Tom
KeymasterHi Ben,
Yes, you will have to grab each custom field separately, and then echo them in your desired areas.
April 10, 2018 at 6:49 pm #4166Ben
ParticipantHi Tom, forgot to say thanks for this…
January 23, 2020 at 12:40 pm #12858Gwen
ParticipantI’ve implemented your suggestion above to add my “custom_content” ACF field to wpsp_after_title because I’m not using WP’s default content field. However, it renders ALL of that ACF field’s content and I would like it to only display an excerpt of 50 words.
What additional code do I need to add to your suggested code above so that it will only display an excerpt?
Thanks, Tom!
January 23, 2020 at 6:03 pm #12870Tom
KeymasterYou could try this function:
function gwen_limit_text( $text, $limit ) { if ( str_word_count( $text, 0 ) > $limit ) { $words = str_word_count($text, 2); $pos = array_keys($words); $text = substr($text, 0, $pos[$limit]) . '...'; } return $text; }
Then, in your hook, do this:
gwen_limit_text( $your_custom_field, 50 );
50
being the word limit.January 26, 2020 at 7:18 am #12905Cris
ParticipantHi Tom,
Your code works well with custom field but I also need to do the same with several taxonomies. How would it be done?
ThanksJanuary 28, 2020 at 6:30 pm #12987Tom
KeymasterThe custom meta code? What about taxonomies are you customizing? That code should work for everything if a custom field exists.
January 29, 2020 at 1:13 am #12995Cris
ParticipantHi
I used this code for the custom field “precio” and it works correctly:
add_action( ‘wpsp_before_content’,’wpsp_add_custom_meta’);
function wpsp_add_custom_meta()
{
$meta = get_post_meta( get_the_ID(), ‘precio’, true );
if ( isset( $meta ) && ” !== $meta )
echo $meta; echo “€”;
}I want to do the same with 2 taxonomies (similar to categories), not custom fields, but that code does not work with them.
-
AuthorPosts
- You must be logged in to reply to this topic.