Skip Navigation

[Resolved] Split: Using Types to create Events

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display ACF relationship posts

Solution:
You should create a custom shortcode and add it to your theme's functions.php file to get ACF relationship post.

You can find proposed solution, in this case with the following reply:
=> https://toolset.com/forums/topic/split-using-types-to-create-events/page/3/#post-1071238

Relevant Documentation:

This support ticket is created 6 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.

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 37 replies, has 3 voices.

Last updated by keithW 6 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#952027

Luo,

Perfect... that did the trick.

The remaining question I have might be a bit trickier though.

As you saw in the code, we have three data- tags (data-item-type, data-capabilities, data-people) on the parent div which we use for filtering/sorting on the page. I can load the event category into the data-item-type fine but the data-capabilities and data-people tags will take more action.

On the events CPT we have two ACF relationship fields which load dynamically in the list of practice areas and attorneys so we can toggle on the capabilities and people associated to the event. These are categories that we allow the page to filter on so I need to get the values from the ACF fields loaded.

Normally we'd do this via PHP:

$posts = get_field('practice_areas');
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
$pa_title = get_the_title();
echo "$pa_title ";
endforeach;
wp_reset_postdata();
endif;

How can I do this via the View Template section since we need to use that to tie into the repeatable groups for types?

#952031

Hello,

Please elaborate the questions with more details:
How do you setup the ACF relationship fields? With Advanced Custom Fields Plugin?

How and where do you want to get the values from the ACF fields loaded?

If it is a custom field, you can try the Views shortcode [wpv-post-field] to display it, see our document:
hidden link
If it is a custom taxonomy, please try the shortcode [wpv-post-taxonomy
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-taxonomy]

#952040

Luo,

The relationship fields are setup via the Advanced Custom Fields plugin.

I want to load the values from the ACF into the Views Template. I tried adding [wpv-post-field name="practice_areas"] to the view template but nothing is being returned.

#952144

So it is a compatibility problem between Advanced Custom Fields plugin, please provide a copy of your website, also point out the problem page URL, problem custom field, how and where do you want to display it.
I need to test and debug it in my localhost
https://toolset.com/faq/provide-supporters-copy-site/

#952419

Forgot to include admin login details

username: lisiadmin
password:

#953456

Minesh
Supporter

Languages: English (English )

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

Luo is on vacation. This is Minesh here and I'll take care of this ticket and try to help you further to achieve solution you were looking for. Hope this is OK.

I try to download the file but it takes ages - could you please upload the file on some file sharing service like google drive or dropbox and send me a link to download the file.

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

#953608

Minesh,

I’m also away on vacation. Can you try downloading the file again? Otherwise I’ll need to get back to you with the files next weekend.

#953619

Minesh
Supporter

Languages: English (English )

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

OK - I will try to download it otherwise please send me duplicator package next week. I will update you here.

#954416

Minesh
Supporter

Languages: English (English )

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

Well - I installed the duplicator on my localhost and now I would like to know what you need to display and where exactly.

To query repeatable fields group items you can use the Types PHP API function toolset_get_related_posts() .
For example:

$results = toolset_get_related_posts(
$post->ID,     // the parent post
'columns-layout',   // the RFG slug
'parent',     // the RFG role in this relationship is 'child'
100,     // the maximum number of results
0,           // the offset
array('meta_key'=>'toolset-post-sortorder'),     // additional query arguments
'post_object',   // return format
'child',    // role to return
'meta_value_num',
'ASC'
);

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

#958216

Minesh,

I'm back from vacation. Thanks for downloading and setting up the site. Here's a breakdown of what I'm trying to do.

On this page, hidden link, I'm using the View "Display Events on Events page" and "Display Past Events on Events page" for this page which look like this:

<div class="events-result-item" data-item-type="[types field='event_category'][/types]" data-capabilities='[wpv-post-field name="practice_areas"]' data-people='[]'>
<div class="details">
<div>
<img src="/wp-content/themes/cohenseglias/images/ion-calendar.svg" alt="calendar">
<span class="date">[types field='event_date' style='text' format='M j, Y'][/types]</span>
</div>
<div>
<img src="/wp-content/themes/cohenseglias/images/ion-clock.svg" alt="clock">
<span>[types field='event_time'][/types]</span>
</div>
<div>
<img src="/wp-content/themes/cohenseglias/images/ion-location.svg" alt="location">
<span>
<span>[types field='event_location'][/types]</span>
</span>
</div>
</div>
[wpv-post-title item="@event_dates.parent"]
</div>

As you can see in the code, we have three data- tags (data-item-type, data-capabilities, data-people) on the parent div which we use for filtering/sorting on the page. I can load the event category into the data-item-type fine but the data-capabilities and data-people tags will take more action.

On the events CPT we have two ACF relationship fields which load dynamically in the list of practice areas and attorneys so we can toggle on the capabilities and people associated to the event. These are categories that we allow the page to filter on so I need to get the values from the ACF fields loaded.

Normally we'd do this via PHP:

$posts = get_field('practice_areas');
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
$pa_title = get_the_title();
echo "$pa_title ";
endforeach;
wp_reset_postdata();
endif;

How can I do this via the View Template section since we need to use that to tie into the repeatable groups for types or is there a different way to handle all of this via PHP directly?

#958731

Minesh
Supporter

Languages: English (English )

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

So as I understand, how the field "practice_areas" is setup? as repeating field or repeating field group?

#972026

practice_areas is a relationship fields setup with the Advanced Custom Fields Plugin.

#1064049

Minesh
Supporter

Languages: English (English )

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

Well - what if you wrap the code to custom shortcode.

For example:

function func_get_practice_areas( $atts ){
$posts = get_field('practice_areas');
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
$pa_title = get_the_title();
echo "$pa_title ";
endforeach;

}
add_shortcode( 'acf_practice_areas', 'func_get_practice_areas' );

And then call the shortcode [acf_practice_areas] with data-capabilities attribute of HTML.

#1069390

Thanks for the example. Creating shortcodes is all new to me so I took your example and tried to find some other help docs to make it work but I haven't had any luck. It seems like something is being passed to the shortcode to generate the correct output as I am getting no output. Below is what I've added to the functions.php file:

add_filter('wpv_custom_inner_shortcodes', 'prefix_add_my_shortcodes');
function prefix_add_my_shortcodes($shortcodes) {
$shortcodes[] = 'acf_practice_areas';
return $shortcodes;
}
function func_get_practice_areas( $atts ){
$posts = get_field('practice_areas');
if( $posts ):
foreach( $posts as $post):
setup_postdata($post);
$pa_title = get_the_title();
return "$pa_title test";
endforeach;
endif;
}
add_shortcode( 'acf_practice_areas', 'func_get_practice_areas');

I'm returning $pa_title test in an attempt to atleast get "test" to output, but that isn't happening. If I remove the if( $posts ): and foreach( $posts as $post): parts, I can get it to return a number and test (example: 1046 test). Looking into the database, 1046 seems to represent the RFG setup for that event so I'm guessing it's not passing the correct postid for the parent event? Any further ideas on how to get this to work or troubleshoot further to figure out what isn't working?

Alternatively if there's a way to setup this page using straight PHP rather then Views, I'm up for that too.

Is there someone there who I can talk with a little more frequently then once a day to try and get this wrapped up?

#1069994

Minesh
Supporter

Languages: English (English )

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

Well - I think we are so near. Could you please share wp-admin and FTP access details so I can look at it and also tell me what should be the expected value for data-capabilities with test case URL.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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