Skip Navigation

[Resolved] Sort by date post relationship

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

Problem:
In a many-to-many relationship the client wants to display related posts, sorted by a field on the related posts.

Solution:
The current implementation of many-to-many relationships involves creating an intermediate post type, and then creating a View which returns the intermediate posts with a filter for the parents on one side, while using the id attribute to display content from the parent on the other side.

That View can only filter by fields present on the intermediate post type itself, which means duplicating the field in question from the parent on the intermediate posts.

This will become redundant with the switch to Types 3.0, when it will eventually be possible to filter by fields of related posts.

This support ticket is created 6 years, 10 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 26 replies, has 2 voices.

Last updated by olivierF 6 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#629662

there is always a problem, the agenda is not complete and only appears for one artist. I do not understand where the problem comes from.
Thanks for your help

#629699

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I'm not sure from your comment what the issue is.

Because you use conditional shortcodes in your View I made a small edit to simply output the participant post title and the concert date field of the participant.

You can see that it seems to be working correctly on the pale grey artist page: hidden link

Not all of the concerts appear, but I don't know how you create this page, I cannot see any template, but I'm guessing that where you insert the View for the concerts you have set a limit parameter.

Presumably that is why there is an Agenda Complet button which takes you to another page where you can see all concerts.

#629701

there is no limit, there are missing dates, the dates of April are not displayed when they should be before June?

#629702

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

How do you make that page? Where is the View inserted?

#629716

There is the code of inserted view :

<?php echo do_shortcode('[wpv-view name="agenda_artiste" ]');?>

there is the code of the template "single artist" :

 <?php
/**
 * Template Name: single-artist
 */
get_header(); ?>

<div class="container">
		<div class="row equal">
			<div class="col-xs-12 col-sm-6">
				<div class="white-inner"><?php echo do_shortcode('[types field="artiste-image" size="news-thumb" class="img-responsive"][/types] ');?></div>
			</div>
			<div class="col-xs-12 col-sm-6">
				<section class="band-details">
					<h2><?php echo do_shortcode('[wpv-post-title]');?> <span class="nationalite"><?php echo do_shortcode('[types field="artiste-nationalite"][/types] ');?></span></h2>
					<h3><?php echo do_shortcode('[wpv-view name="liste_categories_vue" ]');?></h3>
					<?php echo do_shortcode('[types field="artiste-description"][/types] ');?>
					<div class="row album-shop-section">
						<div class="col-xs-12 socials">
						<?php echo do_shortcode('[wpv-view name="reseaux_sociaux_artistes_vue" ]');?>
						</div>
					</div>
				</section>
			</div>
		</div>
	<div class="row">
			<div class="col-sm-6 col-xs-12">
			<?php echo do_shortcode('[wpv-view name="artiste_video_vue" ]');?>
			<?php echo do_shortcode('[wpv-view name="agenda_artiste" ]');?>
			</div>
			<div class="col-sm-6 col-xs-12">
			<?php echo do_shortcode('[wpv-view name="discography_vue" ]');?>
			</div>
		</div>
</div>
<?php get_footer(); ?>
#629986

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Olivier

I spent a long time trying to understand why some of the concerts weren't showing up and in the end it appears that the code snippet I proposed to run one time to copy the concert fields had not been run, so some of the participant posts had the concert date and others didn't, and so ordering by the concert date field was not including posts with no concert date.

I ran the code and it now appears to be working: hidden link

#629997

Hi Nigel,

there is always the same problem, sorting is not done in order of concert date but by date of publication, when I sort by concert date, nothing is displayed or only a few dates.
Thank you for your precious help.

Olivier

#630003

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, you are right, I had switched the order by date while testing. Switching it back I see there is still the problem.

Hmm.

I'll get back to it a little later today and try and see why it's not working.

#630042

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK. The problem in the end was ridiculously simple.

I had given you that code snippet that registers a function to copy the custom fields — but we didn't run the function. :facepalm:

It's working now 🙂

#630057

Thank you Nigel, it's beautiful 😉
There is still a small problem, when I want to show only dates later or below today in the query filter, nothing is displayed, I guess it is still missing a little detail?

Olivier

#630087

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

That one was fairly easy.

Dates are stored as UNIX timestamps (numbers) in the database, and so the date filter needs to compare the value as a number.

I updated that and it is working.

(The site looks really nice, by the way.)

#630098

Thank you Nigel,
Everything is perfect, thank you very much for your help 😉