Skip Navigation

[Resolved] Custom Field Accordeon

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1300369

I want to make custom field like an accordeon repeater field.
So my clien can make accordeon in the backend under the post and with shortcode i place it anywhere.
I dont want to use custom post type for that.
but i dont found the solution in toolset... how i i can set up this?

#1301225

Hi Christoph,

Thank you for contacting us and I'd be happy to assist.

You can use a Toolset post view to show an accordion, with data coming from a repeating field group.
( example of the accordion: hidden link )

Here are the steps:

1. Please make sure that "Toolset should load Bootstrap 4" options is selected at WP Admin -> Toolset -> Settings -> General.

2. Next, you'll add a repeating field group, for the post in which you'd like to show the accordion. In this case, I'm using the post "Project" as an example.
( ref: https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/ )
( screenshot: hidden link )

3. Each accordion item will need to have two fields, title, and the content, so you'll add a single line type field for the title and a WYSIWYG field for the content in this new repeating field group
( screenshot: hidden link )

4. These fields will show on each Project post's edit screen so that the client can add as many accordion items as needed.
( screenshot: hidden link )

5. To show this data on the front-end in an accordion, you'll create a new post view and set it to get results from this new repeating field group.
( ref: https://toolset.com/documentation/getting-started-with-toolset/create-and-display-custom-lists-of-content/ )
( screenshot: hidden link )

6. Since your goal is to show accordion from only those items which are added with the post that is being viewed, you'll add a query filter, with an option: "The post where this View is shown".
( screenshot: hidden link )

7. In the "Loop Editor" section, you'll add the content wrapped in an accordion container:
( screenshot: hidden link )


[wpv-layout-start]
	[wpv-items-found]
	<div class="accordion" id="accordionProject">
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="loop-item-in-view-to-show-project-accordion"]
	</wpv-loop>
	<!-- wpv-loop-end -->
    </div>
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Note: Please replace "loop-item-in-view-to-show-project-accordion" with the actual slug of your view's content template.

8. In the view's template, you'll add the code for each accordion item, along with the custom fields shortcode like this:
( screenshot: hidden link )


<div class="card">
  <div class="card-header" id="heading-[wpv-post-id]">
    <h2 class="mb-0">
    <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapse-[wpv-post-id]" aria-expanded="true" aria-controls="collapse-[wpv-post-id]">
      [types field='accordion-item-title'][/types]
    </button>
    </h2>
  </div>

  <div id="collapse-[wpv-post-id]" class="collapse" aria-labelledby="heading-[wpv-post-id]" data-parent="#accordionProject">
    <div class="card-body">
      [types field='accordion-item-content'][/types] 
    </div>
  </div>
</div>

Note: Please replace "accordion-item-title" and "accordion-item-content" with the actual slugs of your title and content fields.

9. As a result, when you'll insert this newly created view's shortcode inside any Project post, it will show an accordion, from items added with that post.
( screenshot: hidden link )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar