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?
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.
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.
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.
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!
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' );
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?
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.
Ah yeah I don't know why I didn't think of that, perfect solution! 🙂 Cheers.
Help much appreciated, have an awesome week.