Skip Navigation

[Resolved] View shortcode attribute when using a custom field its not working

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use the value of a Types field in a shortcode attribute but it does not seem to be working.

Solution: Be sure to use the raw output attribute in the Types field shortcode to prevent extra markup from breaking the filter.

This support ticket is created 3 years, 11 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by matthewL-7 3 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1645621

Hi,

I am trying to pass a custom fields value in a shortcode attribute on a view.

See the code here;
[wpv-view name="category-search-results-promo-codes-list-for-a-retailer" retailerid="[types field='retailer-advertiser-id'][/types]"]

However the site gets a critical error on that page when I use "[types field='retailer-advertiser-id'][/types]" in the retailerid shortcode attribute.

If I hard code a value e.g. say a random number it works fine.

Any idea why its getting a critical error?

#1646547

First try using the raw output attribute in the Types field shortcode to eliminate any extra formatting or spaces:

[wpv-view name="category-search-results-promo-codes-list-for-a-retailer" retailerid="[types field='retailer-advertiser-id' output='raw'][/types]"]

If this does not solve the problem, output the value of the field before the View so you can see the value on the front-end:

Raw: [types field='retailer-advertiser-id' output='raw'][/types]<br />
[wpv-view name="category-search-results-promo-codes-list-for-a-retailer" retailerid="[types field='retailer-advertiser-id' output='raw'][/types]"]

Then we can check the query filter settings to see why the raw value is causing an error.

#1647727

Hey

So using the raw output helped quite a bit, most of the categories which display the view now work but quite a few don't.

A few just don't load the page entirely. I am fairly sure its because on the pages that don't load some of the posts don't have a Retailer ID.

If they don't how can we get it to not kill the entire page due to this?

See for example: hidden link
hidden link

But this category - hidden link works absolutely fine.

Thanks.

#1647789

Not sure offhand, can you share the details of the error message from the server logs? If you're not familiar with server logs, I can show you how to activate them temporarily. Go in your wp-config.php file and look for

define('WP_DEBUG', false);

Change it to:

define('WP_DEBUG', true);

Then add these lines, just after the WP_DEBUG line:

define('WP_DEBUG_LOG', dirname(__FILE__) . '/error_log.txt');
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
define('WP_DISABLE_FATAL_ERROR_HANDLER',true);

Refresh one of the pages that throws an error. This should create an error_log.txt file in your site's root directory. Use FTP to look for this file in the same directory as wp-config.php. You may need to click "Refresh" in your FTP browser to see a new file appear. Please download this file to your computer, open it in any text editing software, and send me its contents. Once that is done, you can revert the changes you made to wp-config.php and delete the log file using FTP.

If you'd rather just share site login credentials and FTP login credentials I can do this for you and check the View's configurations to see why the error might be thrown.

#1648763

Hey,

No problem I have gone ahead and done that, please see the error log below:

[03-Jun-2020 10:35:08 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/user/public_html/wp-content/plugins/types/vendor/toolset/types/embedded/classes/loader.php on line 91
[03-Jun-2020 10:35:08 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 77824 bytes) in /home/user/public_html/wp-includes/functions.php on line 4609
[03-Jun-2020 10:35:08 UTC] PHP Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
[03-Jun-2020 10:35:20 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/user/public_html/wp-content/plugins/types/vendor/toolset/types/embedded/classes/loader.php on line 91
[03-Jun-2020 10:35:20 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 77824 bytes) in /home/user/public_html/wp-includes/functions.php on line 4609
[03-Jun-2020 10:35:20 UTC] PHP Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

The above is over my head, ha!

#1649269

Okay so the exhausted memory error indicates you should increase the amount of memory for PHP and WordPress from 126M to 256M. You can try adding these lines in your wp-config.php file, or you may need to get your host involved to increase the server memory:

define('WP_MEMORY_LIMIT', '256M');
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
#1650535

Yeah that fixes it but it uses a ton of resources because the ID is not passed it brings in all the posts.

Is there a way with the view if no ID is passed in the shortcode there's like a default e.g. 0? Is there no way to set a default?

#1650703

Ah okay that makes sense. It seems like you should be able to put a conditional wrapper around the View that tests if the retailer ID > 0. Then the View would never even execute for those cases where the ID doesn't exist, bypassing the issue. Whatever you have in the "wpv-no-items-found" section of the View could be copied into an identical conditional set to evaluate="false". Unless I'm misunderstanding what you want to accomplish or you have something more complex desired when no results are found in the View.

#1650825

Ah yeah I don't know why I didn't think of that, perfect solution! 🙂 Cheers.

Help much appreciated, have an awesome week.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.