Skip Navigation

[Resolved] View isn’t returning all entries

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

Problem: I have a View that isn't showing all the results I expect to see.

Solution: In this case, a filter in the View is filtering based on an outdated relationship field. A custom shortcode can produce a list of related post IDs, which can be used in a shortcode attribute to display all the related posts.

This support ticket is created 4 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1341115
Screen Shot 2019-09-16 at 8.18.11 AM.png
Screen Shot 2019-09-16 at 8.18.43 AM.png

I have this query

[wpv-view name="des-moines" limit="-1" offset="0" locationid="465,471,205,198,469,467"] which should display 110 entries, but is only showing 100. 10 are missing. If you look at the pages where I should the individual locations I can account for all 110. Its only when I use this view to consolidate these locations together, it somehow misses 10.

You can view this query in action on
hidden link (production).
hidden link (cloned server)

I'm giving you access to a new clone that I just spun up so that you can easily diagnois problem. I will need to replicate any fix to the production service.

#1341363

Hi, after migrating to the new post relationships system, the old _wpcf_belongs_location_id custom field cannot be used as a filter with any level of certainty. When posts are linked in this relationship after the relationship migration process, this custom field value will not be added to child posts in the relationship. The field will remain in place for posts that were linked before the relationship migration. In the new system, a proprietary data table is used to handle those relationship connections. So I suspect what is going on here is you have 10 items that were linked in this relationship after the relationship migration process was run, and now those items are not appearing in the list of results. That is a quirk of how WordPress filters work, unfortunately. If a custom field is used as a filter, but a post has no value for that custom field, it will not appear in the query results.

Thanks for setting up the staging site, that's very helpful. I can run a few tests on the staging site to confirm my theory, or look for other potential causes. Stand by and I will update you soon.

#1341429

Thanks Christian. I guess I could build 6 different views (one for each location) and then display them together on the same page, they would just be independent of each other. Any other ideas appreciated.

#1341565

That's an option, but I am trying to find a cleaner alternative that doesn't involve too much custom code. I'll have to follow up tomorrow as my day is ending here.

#1341567

Thank you sir!

#1342197

Okay here is an idea. This is a custom shortcode that will return a comma-separated list of child post IDs if you provide a list of parent post IDs and the slug of a post relationship:

add_shortcode('children-of-multiple-parents', 'children_of_multiple_parents');
function children_of_multiple_parents($atts, $content = '') {
  $atts = shortcode_atts( array(
      'parents' => '',
      'relationship' => '',
      'limit' => 1000000,
      'offset' => 0
  ), $atts );

  $children = toolset_get_related_posts(
    // get posts related to this one
    [
      'parent' => explode(',', $atts['parents'])
    ],

    // Relationship between the posts
    $atts['relationship'],

    // Additional arguments
    [
        // pagination
        'limit' => $atts['limit'],
        'offset' =>$atts['offset'],

        //
        'args' => [ ],

        'role_to_return' => 'other',
        'return' => 'post_id'
    ]
  );
  return implode(',', $children);
}

So you would create a View of child posts, filtered by post IDs set by a shortcode attribute "ids". Then you would use this custom shortcode in the View shortcode like this:

[wpv-view name="your-view-of-child-posts" ids="[children-of-multiple-parents parents='465,471,205,198,469,467' relationship='location_public-artwork'][/children-of-multiple-parents]"]
#1342869

Thank you! I will try this later this week.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.