Use serialized array from dc:post:meta

I have a layout for a CPT that uses {{dc:post:meta key="_sfwd-courses"}}

This meta is stored in the database as a serialized array. I need to get the value for the key sfwd-courses_course_price, which in my case is 12.99, out of this serialized array.

What is the best way to go about doing this?

Example of serialized array:

a:32:{i:0;s:0:"";s:30:"sfwd-courses_course_price_type";s:6:"paynow";s:40:"sfwd-courses_course_prerequisite_enabled";s:0:"";s:32:"sfwd-courses_course_prerequisite";s:0:"";s:40:"sfwd-courses_course_prerequisite_compare";s:3:"ANY";s:34:"sfwd-courses_course_points_enabled";s:0:"";s:26:"sfwd-courses_course_points";s:0:"";s:33:"sfwd-courses_course_points_access";s:0:"";s:26:"sfwd-courses_expire_access";s:0:"";s:31:"sfwd-courses_expire_access_days";i:0;s:42:"sfwd-courses_expire_access_delete_progress";s:0:"";s:36:"sfwd-courses_course_price_billing_p3";s:0:"";s:31:"sfwd-courses_course_trial_price";s:0:"";s:37:"sfwd-courses_course_trial_duration_t1";s:0:"";s:37:"sfwd-courses_course_trial_duration_p1";s:0:"";s:36:"sfwd-courses_course_price_billing_t3";s:0:"";s:25:"sfwd-courses_course_price";s:5:"12.99";s:30:"sfwd-courses_custom_button_url";s:0:"";s:37:"sfwd-courses_course_materials_enabled";s:0:"";s:29:"sfwd-courses_course_materials";s:0:"";s:24:"sfwd-courses_certificate";s:0:"";s:27:"sfwd-courses_exam_challenge";i:0;s:41:"sfwd-courses_course_disable_content_table";s:0:"";s:35:"sfwd-courses_course_lesson_per_page";s:0:"";s:42:"sfwd-courses_course_lesson_per_page_custom";s:0:"";s:41:"sfwd-courses_course_topic_per_page_custom";s:0:"";s:40:"sfwd-courses_course_lesson_order_enabled";s:0:"";s:34:"sfwd-courses_course_lesson_orderby";s:10:"menu_order";s:32:"sfwd-courses_course_lesson_order";s:3:"ASC";s:46:"sfwd-courses_course_disable_lesson_progression";s:0:"";s:37:"sfwd-courses_course_short_description";s:549:"In this study, we explore Psalm 119 and discover what it really means to “love” God’s instruction—even in the midst of the most difficult circumstances. ";s:52:"sfwd-courses_course_price_type_paynow_enrollment_url";s:0:"";}

Hey @designerken,

Thanks for writing in!

You may need to run a Looper Provider Array and use the Looper Consumer to display the price.

Kindly let us know how it goes.

@ruenel

That oddly does’t seem to provide any content to loop through.

Hello @designerken,

Regretfully the given password is incorrect. We cannot log in using the given credentials. In the meantime, can you check out if you can use {{dc:post:meta key="_sfwd-courses.sfwd-courses_course_price"}} to display the price?

Thanks.

@ruenel

I tried your suggestion and that didn’t seem to change anything. I have verified credentials and they appear to work on my end.

Hey @designerken,

Sorry for the confusion. I edited your Untitled page and use Looper Provider Dynamic Content. I run a Looper Consumer and used {{dc:looper:field key="sfwd-courses_course_price"}} to display the price.

Please check out that page now.

Thanks.

Hello @ruenel,

That looks to do the trick! I appreciate the assist. So many options with these loopers. How would I have known to use dynamic content to go though that looper? Especially when your initial suggestion was to use the array provider.

Thanks again. Cheers.

Hey @designerken,

Yes, I suggested the Looper provider Array because of the array that you have provided. When I logged in, I just played around with Looper Provider Array and the Looper Provider Dynamic Content. Both of these accept dynamic content by the way. One thing you also need is that when you have a looper provider, you must also have a looper consumer which was previously missing when you tested it out.

Cheers.

@ruenel

Yes, I was aware I took the Looper Consumer off the element during the testing as it was completely hiding the text element in Cornerstone when trying to add the content in the element. I would turn on consumer once I finished adding the content in the text element.

I had never seen this behavior before where it was simply not showing the element in the builder. Even when I had text other than the dynamic content in the text. For example:
Price: ${{dc:looper:field key="sfwd-courses_course_price"}}<br /> normally I would still see the text Price: $ output on the screen even if there was nothing to output from the dynamic content. But in this case the whole element was not visible in the builder, but it was still there in the document nav sidebar.

Hi @designerken,

It seems that your issue has been resolved already.

Best Regards.

Hello @ruenel,

Sorry for any confusion. I was simply replying to your comment:

Yes, I suggested the Looper provider Array because of the array that you have provided. When I logged in, I just played around with Looper Provider Array and the Looper Provider Dynamic Content. Both of these accept dynamic content by the way. One thing you also need is that when you have a looper provider, you must also have a looper consumer which was previously missing when you tested it out.

When I was trying the options you originally gave about using the Looper Array or different keys, and I had the consumer on the element, the whole element would be hidden from view in Cornerstone. Just seems odd that it would completely disappear. I have updated the Untitled Page again with a new section to show this.

Maybe you can take a look and provide insight as to why it is happening? I don’t recall Cornerstone doing this in the past.

Hello @designerken,

It seems that the Looper Provider Array does not accept the serialized array format. I already have reported this to our developer so that they can investigate further. For now, just use the Looper Provider Dynamic Content to display those prices.

Thank you for your understanding.

@ruenel

It seems that the Looper Provider Array does not accept the serialized array format. I already have reported this to our developer so that they can investigate further. For now, just use the Looper Provider Dynamic Content to display those prices.

Yes, I agree and understand the solution for now is to use Dynamic Content to show prices.

My follow up was regarding the turning off the consumer because the text field was not showing up in Cornerstone even though there was a regular text element in the div. Is this due to the bug of not being able to use serialized data in the array or something else going on?

Hello @designerken,

When you have a Looper, The Provider will provide the source and you still need to enable a Looper Consumer before you can display any data from the source. This is why, when you turn OFF the Looper Consumer, the text did not display anything.

Hope this helps.

@ruenel

I guess we are not going to be on the same page here. I don’t know if I am not explaining the use case clearly enough here or what. As stated I turned off the consumer because the entire text element was not being shown, even when there was no dynamic content in the text element.

Regardless if there was a consumer or not, it should still render a the elements nested in the provider.

Hello @designerken,

I think I get what you mean.

When you turn ON the Looper Consumer, the Text element does not display because there was nothing to consume even if you have inserted some text content. Our Looper Provider returns NULL or no items and this would stop the Looper Consumer from returning anything.

As soon as you disable the Looper Consumer OFF, the Text element displays.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.