Skip Navigation

[Resolved] Be able to group posts by field.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 4 replies, has 1 voice.

Last updated by nikolasS 4 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2800240

Tell us what you are trying to do? Be able to group posts by field. e.g. partners per country

Is there any documentation that you are following? no

Is there a similar example that we can see?
hidden link

What is the link to your site?
hidden link

#2800241

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share bit more information about your content structue.

How you setup country field and what posts you want to group by country?

Is country setup as taxonomy?

#2800243

I have created a custom post (Partner) with custom fields. One of which is Country.
then i want to list the Partners grouped by Country.

#2800245

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It will be easier for you if you setup "country" as custom taxonomy. Would you like to change the structure accordingly?

#2800246

i prefer to be able to do it with custom field. is there a way?

#2800254

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Have you created page and view. I would like to know how exactly you want to display the output and grouped posts by country.

Can you please send me problem URL and admin access details. You should just build your view without grouping so I know how exactly you want to display the output.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2800275

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I can help you to group post by custom field but you will have to deal with how to display such data with accordion etc..

Can you please check now: hidden link

I've set your view to order by the coutry custom field:
=> hidden link

Then I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_shortcode('groupby_country', 'func_group_by_custom_field_country');
function func_group_by_custom_field_country($atts, $content = '') {
  static $country = null;
 
  $condition = $atts['condition'];;
  $value = $atts['value'];;
  switch ($condition) {
    case 'country':
    if ($$condition != $value) {
        $$condition = $value;
        return wpv_do_shortcode($content);
      }
      break;
  }
  return '';
}

And added the shortcode block within your view's loop area and added the following to call the above shortcode:

[groupby_country condition="country" value='[types field="country"][/types]']
<div style="text-align:center;"><h4><strong>[types field='country'][/types]</strong></h4></div>
[/groupby_country]

As you can see with the following screenshot:
- hidden link

More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code

#2800296

ok. this is quite clever.
But ... It does not actual group them.
I have tried to use a View with a specific selection of filter. But when i tried to duplicate that view in the same page it just duplicated the reference to the view. so whenever i change the value in on view it changes to all views.
Check: hidden link

#2800355

I have tried to create a content template that accepts a shortcode parameter. then use this content template in my page and pass in the country code.
But it does not seem to work.
Check: hidden link

#2800361

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

At start your requirement is different and in middle of the ticket you change your requirement that is not how we suppose to give support.

You said you want to group posts by country that query is already been addressed and solution provided. if you have different question and requirement as stated before pleaes feel free to close the current ticket as issue is already been addressed and open a new ticket with every new question you may have. This will help other users searching on the forum as well as help us to write correct problem resoluiton summery.

#2800362

ok. thanks