how do create post template for CPT

Posted in: Newspaper
Post count: 162

Dear Team,

I feel a bit lost with a problem.

I have a custom post type for Quizzes that I created using WordPress’ Metabox API & not ACF. It is like a plugin.

Now when I create a quiz, with a question, and options and marking the correct answer, how do I map the display of the quiz to a CPT Template?

If anyone else has tried something like this, am all ears for solutions!

Post count: 27744

Hi,

If the cpt appears in the cloud templates -> CPTs/Taxonomies, then there you can assign a template, and you can create the quizzes in the Gutenberg editor.

Thank you!

Post count: 162

Hi Anamaria,

Yes, the cpt appears in the cloud templates and I assigned a template too. But in the template, only the “Title” & “Description” appears – the data from the Metabox doesn’t. This data is the quiz question and options.

Also, none of my custom posts open the Gutenberg Editor.

Where am I going wrong?

Post count: 27744

Hi,

Did you have to create a quiz in the Gutenberg editor? Can you please provide a video?

Thank you!

Post count: 162

Here’s a link to the video! I’d of course be working on the custom post type a bit more — am in the initial stages only, so your help is appreciated!

Post count: 27744

Hi,

Can you send the link to the plugin?
I thought you created the quiz in the content, but these are custom fields, which is why they’re not displayed in the template. They will need to be added, but to be able to assist you, I need the plugin to attempt to create a test.

Thank you!

Post count: 162

Hey! Sure – but how do I send it? I made it myself (and it isn’t perfect yet) — but can email you access to the WP backend / Siteground whatever you prefer. Sorry am also trying this for the first time as none of the plugins I’ve seen are helpful to my purpose.

Post count: 27744

Hi,

I think that you may use a plugin created for this and then to add it to the content https://www.wpbeginner.com/showcase/best-quiz-plugins-for-wordpress/

Thank you!

Post count: 162

I’m not sure I follow – I don’t want to use any of the plugins listed here because my expectations / needs are specific. I have tested some of these including HD Quiz and don’t need these.

Could you please guide me on making sure the question loads into the CPT template or my normal single-post template? I would prefer that the quiz loads into the single-post template like a usual post.

Post count: 27744

Hi,

From what I saw, you have a custom implementation, so I think you need to change the files. Are you working on localhost or a website for testing, and can you give us access?

Thank you!

Post count: 162

Hi @Anamaria,

Sorry for my late response – I was still testing it on my actual site and not a staging one, so unfortunately I was a bit stuck. It turns out my trial wasn’t working and your instructions here to use CPT-ACF might be a better solution.

I have read through the ACF Pro documentation, and I feel it might be a better idea for me to create a quiz using repeater fields etc. and then map it to a template provided by you all.

Would you know of use-case examples such as these?

Thank you in advance!

Post count: 27744

Hi,

Unfortunately, this type of acf is not implemented in the theme, but you can use the shortcode of acf to display it using column text https://support.advancedcustomfields.com/forums/topic/repeater-field-shortcode/

Thank you!

Post count: 162

Hi @anamaria – thanks for sharing the link but it seems the good option is to add the code to a page-template. Somehow, adding a code to functions.php and generating a shortcode is just not giving out the right solution in case of ACF’s nested repeater fields.

How can I add the code to a blank template assigned to my CPT?

Post count: 27744

Hi,

Unfortunately, you can not add the code to the template because errors can appear. Custom work can add compatibility for that type of acf.

Thank you!

Post count: 162

Hi @Anamaria, I managed to do this and generate a shortcode that I can add to any page / post to display the quiz (not the front end creation for it yet). However, I’ve added it to my functions.php code. I don’t use a child theme yet.

Please suggest how I can update the theme without losing this. Should I move to a staging site, create a child theme and then update? How to copy everything to a child theme?

Post count: 27744

Hello,

You can create a child theme or, after every update, add the code to the functions file again https://forum.tagdiv.com/the-child-theme-support-tutorial/

Thank you!

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