Shortcode within CPT

Posted in: Newspaper
Post count: 70

I have thousands of pages using a CPT I have set-up on the site.

Within this CPT I have created a custom field called ‘Statement’. Within this field, I am using a slightly different shortcode for each page (e.g. [eod_financials target=”AAPL.US” id=”10329343″ preset=”Income Statement” years=”2018-2023″]). The “AAPL.US” section of the share price-related shortcode is the only part that changes.

I have loaded the custom field metadata to the site for each page and am referencing that by using the ‘Custom Field’ attribute and choosing ‘statement’ from the list within Composer, but it is only showing the shortcode text, rather than rendering the actual shortcode.

I know the shortcode works.

What am I doing wrong?

Post count: 27744

Hello,

Our element Custom Field is only compatible with these field types text, URL, email, textarea, number, select, checkbox, radio, and button group.
So, if it is a shortcode you can add it using column text.

Thank you!

Post count: 70

So, how would I add a different shortcode to each of the 10,000 pages I have automatically?

I have a page for Apple, a page for Microsoft, a page for Amazon, etc, etc.

Thanks in advance.

Post count: 27744

Hello,

Please let me know the type of custom field, in the future, we want to add more types to be supported.

Thank you!

Post count: 70

We need to be able to call shortcodes from the Custom Fields. I had assumed that the ACF plugin would do this, but apparently it doesn’t. Its a pretty big gap in the functionality.

For your reference, we are looking at including premium stock information from some data vendors using the Financial Stocks & Crypto Market Data Plugin (https://wordpress.org/plugins/live-stock-prices-for-wordpress/).

To do this, we would create a field and upload the variations of the shortcodes to each of the 10,000 companies we cover.

The shortcodes work perfectly well when adding them statically to a template, but we cannot find a way of adding them dynamically to CPT.

Post count: 27744

Hello,

Unfortunately, I don’t understand the process by which you want to implement it, i.e. these are the types of custom fields, do you use one from here or not? I need more specific details to understand what you want to achieve.

You can try to use this option and check if it works https://www.advancedcustomfields.com/resources/shortcode/

Thank you!

Post count: 70

Easiest way to explain it:

I am using CPT and ACF to create a new post type.

I have then used this new post type for 10,000 posts, with each post featuring information on a seperate company (Microsoft, Apple, Amazon, etc).

Within this post type I want to feature a unique shortcode to display the share price and share history of each company (e.g. Amazon’s share price on the Amazon post).

This equates to creating 10,000 seperate shortcodes and uploading them to the site as a field.

I have done this, but the Custom Field within Composer seemingly will not display the content of the shortcode. It just returns [shortcode] text.

Because of this I need to find an alternative.

Hope this makes more sense!

Post count: 27744

Hi,

Unfortunately, I did some tests and there is no option to do it with a custom field.

Thank you!

Post count: 70

Thanks for trying. Do you know of any other way I could get this to happen?

Post count: 70

Further to the conversation, I have found a solution. Worth noting for future development of the template.

I’ve just added the line to the bottom of the functions file:

add_filter(‘acf/format_value/type=textarea’, ‘do_shortcode’);

Whilst this has a drawback re all fields matching ‘textarea’ now doing shortcodes, it does seem to work.

Post count: 27744
Post count: 70

Thanks for that Anamaria – I’ll check it out.

Post count: 70

Just a quick update on this:

I have noticed that whilst I can now display the shortcode in a custom field, for some reason it only displays the content of the shortcode when I go into WordPress admin and manually save each post. I don’t have to make any edits. Just save.

Do we have a solution so that I do not have to manually save each and every post?

I have tried Bulk Edit within WordPress Admin, but that doesn’t work.

Thanks in advance.

Post count: 27744

Hi,

Unfortunately, you need to do it for each post.

Thank you!

Viewing 14 posts - 1 through 14 (of 14 total)
The forum ‘Newspaper’ is closed to new topics and replies.