Skip Navigation

[Resolved] Truncate WYSIWYG Custom Field

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.18 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Adrian Robbins 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1572495

We are trying to build a very simple search, based on two select drop-downs, which is currently displayed on the Home Page.

So we have got the map markers displaying and the simple search works. If you select Atlantic Salmon it displays just Glenavon. Change to Deer Stalking & Hunting and it displays Glen Tanar & Glen Avon.

However we want to automatically truncate the full narrative from the WYSIWYG "Overview" custom field. Also create the links to the custom posts from the Image, Map Markers and also a button below the truncated narrative (not added this yet). All very basic stuff. But so far we have not been able to get it working.

We have been trying to follow some past support posts and added the truncate PHP code to the child theme functions.php file. But cannot find where you can edit the standard shortcode to add the new truncate code.

Must be missing something very simple? We can see the shortcode in the side bar, but not where you can actually edit?

Can you please point us in the right direction? We are using the latest blocks editor.

The site URL is hidden link

The custom post URLs are hidden link and hidden link

#1573069

Hi Adrian,

Thank you for contacting us and I'd be happy to assist.

To suggest the best way to achieve this, I'll need to see exactly how this view is set up in the admin area.

Can you please share temporary admin login details along with the link to the past support thread(s), that you were trying to follow?

It would also help if you could share a link to an example page where this truncate functionality is working.

Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1577323

Just wondering if you could give an indication as to when our support message https://toolset.com/forums/topic/truncate-wysiwyg-custom-field/#post-1573187 which we sent on Friday 3 April will be processed?

Kind regards
Adrian

#1577515

Hi Adrian,

Thank you for waiting and sorry about the delay in getting back on this.

1. Truncating long field's text:

I found a custom shortcode in your website's active theme's "functions.php" file and was able to make it work, after slight modifications:

Updated code:


function custom_trim_field( $atts, $content = null ) {
    // Extract any arguments passed
    extract( shortcode_atts( array(
        'length'    => 40, // Number of words to show
        'more'      => ' Read More...',  // Text to show at the end of the filtered text
        'field'     => ''
    ), $atts ) );
    global $post;
    if ( empty($field) ){
        return;
    }
    if ( !isset($post) ){
        return;
    }
    $field = wp_strip_all_tags(types_render_field($field, array("raw"=>"true")));
     
    $excerpt_more = apply_filters('excerpt_more', $more); // Create excerpt length to excerpt_more filter
    $readmorelink = '<a href="'.get_permalink($post->ID).'">'.$excerpt_more.'</a>';
    $output = wp_trim_words( $field, $length, $readmorelink );  // create the filter text

    return $output;  // return filter text
      
    //example: [trimfield length="50" more="Carry On..." field="FIELDNICENAME"]
}
add_shortcode( 'trimfield', 'custom_trim_field' );

Here is how it can be used in the content:


[trimfield length="80" more="Carry On..." field="overview"]

Feel free to replace length (80), more text (Carry On...) and target fields slug (overview), as needed.

Note: For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

2. Accessing the shortcode text in the "Fields and Text" block:

When a shortcode is inserted in a "Fields and Text" block, it can be edited by switching to the "HTML" mode:

Example screenshot: hidden link

3. Post link to the image in the "Fields and Text" block:

You have the following shortcode, in the "Fields and Text" block to show the image:


[types field='main-image' title='%%TITLE%%' alt='%%ALT%%' align='center' size='custom' width='300' height='200' resize='crop'][/types]

You can include it in a link tag using the "[wpv-post-url]" shortcode like this:
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-url )


<a href="[wpv-post-url]">[types field='main-image' title='%%TITLE%%' alt='%%ALT%%' align='center' size='custom' width='300' height='200' resize='crop'][/types]</a>

4. Showing search form and the search results in different sections, on the same page:

I'm afraid this is not supported for a view created using the Blocks editor, on the same page.

To achieve this, you have a couple of options:

a). You can use custom CSS code to show the search form, map and the results in different virtual columns.

OR

b). You can remove this view on the home page, recreate it on some other page and then insert that new view on the home page, as an existing view.

When you'll be inserting the existing view, you'll see the option to show either search form and results, only the search form or only the search results.

I hope this helps and please let me know if you need any further assistance around any of these points.

For a new question/concern, please open a new ticket.

regards,
Waqar

#1581035

Hi Waqar

Thanks for you help and I now have the truncation working.

Kind regards
Ade