[Resolved] Custom Fields

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Custom Fields

Tagged: 

This topic contains 33 replies, has 7 voices, and was last updated by  Tom 2 weeks ago.

Viewing 15 posts - 1 through 15 (of 34 total)
  • Author
    Posts
  • #205

    David
    Participant

    Will 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, Dave

    #220

    Tom
    Keymaster

    Hi David,

    It’s already possible with some PHP.

    For example:

    add_action( 'wpsp_before_content','wpsp_add_custom_meta' );
    function wpsp_add_custom_meta()
    {
        $meta = get_post_meta( get_the_ID(), '_your_custom_meta_key', true );
        if ( isset( $meta ) && '' !== $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.

    #261

    David
    Participant

    Thanks, I’ll have a play when I have a moment…
    Dave

    #262

    Tom
    Keymaster

    No problem 🙂

    #2566

    Thierry
    Participant

    Hi 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

    #2576

    Tom
    Keymaster

    Yep, 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 🙂

    #2577

    Thierry
    Participant

    yes of course, great 🙂

    #4089

    Ben
    Participant

    Hi 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,
    Ben

    #4103

    Tom
    Keymaster

    Hi Ben,

    Yes, you will have to grab each custom field separately, and then echo them in your desired areas.

    #4166

    Ben
    Participant

    Hi Tom, forgot to say thanks for this…

    #12858

    Gwen
    Participant

    I’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!

    #12870

    Tom
    Keymaster

    You 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.

    #12905

    Cris
    Participant

    Hi Tom,
    Your code works well with custom field but I also need to do the same with several taxonomies. How would it be done?
    Thanks

    #12987

    Tom
    Keymaster

    The custom meta code? What about taxonomies are you customizing? That code should work for everything if a custom field exists.

    #12995

    Cris
    Participant

    Hi

    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.

Viewing 15 posts - 1 through 15 (of 34 total)

You must be logged in to reply to this topic.