Skip Navigation

[Resolved] View Not Returning Expected Results

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

Problem:

In this user's case they added a filter to their view, however the view was not returning the correct result based on the value provided for the filter.

Solution:

For this I checked the filter and it looked fine, so what I did was to remove and re-add the filter and it started to work fine.

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

Our next available supporter will start replying to tickets in about 3.20 hours from now. Thank you for your understanding.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by jonB-5 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1256989
Screenshot 2019-06-03 at 15.03.52.png
Screenshot 2019-06-03 at 15.03.28.png

I have set up a shortcode that returns the value of a URL parameter if set. If not set this shortcode will return the current post author ID. This code (copied below) works correctly.

// Register Referrer URL Parameter Shortcode
add_shortcode("referrer-id", "referrer_id");
function referrer_id() {

	if (isset($_GET["referrer"])) { // If Referrer is Set in URL Parameter 
		
    	// Get Referrer User Id from URL Parameter
    	$referrerId = $_GET["referrer"];
	
	} else { // Set store branding to product Vendor
		
		$referrerId = get_the_author_meta('ID');
		
	}
  
    return $referrerId;
    
}

I then have a View that should return all posts that have a custom field value that matches the number output by the shortcode. The custom field being checked is a repeating field.

Whilst the shortcode outputs correctly and there are existing posts that should be returned, the view does not return any results.

I have tried re-creating the view from scratch but this did not fix the issue.

The view query results are below...

WP_Query Object
(
    [query] => Array
        (
            [post_type] => Array
                (
                    [0] => trips
                )

            [paged] => 1
            [suppress_filters] => 
            [ignore_sticky_posts] => 1
            [posts_per_page] => -1
            [post__not_in] => Array
                (
                    [0] => 26
                )

            [wpv_original_limit] => -1
            [wpv_original_offset] => 0
            [wpv_original_posts_per_page] => -1
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => approved-agencies-trip-level
                            [value] => 3
                            [type] => CHAR
                            [compare] => =
                        )

                    [relation] => AND
                )

            [post_status] => Array
                (
                    [0] => publish
                    [1] => private
                )

            [meta_key] => wpcf-start-date-and-time
            [orderby] => meta_value_num
            [order] => ASC
        )

    [query_vars] => Array
        (
            [post_type] => Array
                (
                    [0] => trips
                )

            [paged] => 1
            [suppress_filters] => 
            [ignore_sticky_posts] => 1
            [posts_per_page] => -1
            [post__not_in] => Array
                (
                    [0] => 26
                )

            [wpv_original_limit] => -1
            [wpv_original_offset] => 0
            [wpv_original_posts_per_page] => -1
            [meta_query] => Array
                (
                    [0] => Array
                        (
                            [key] => approved-agencies-trip-level
                            [value] => 3
                            [type] => CHAR
                            [compare] => =
                        )

                    [relation] => AND
                )

            [post_status] => Array
                (
                    [0] => publish
                    [1] => private
                )

            [meta_key] => wpcf-start-date-and-time
            [orderby] => meta_value_num
            [order] => ASC
            [error] => 
            [m] => 
            [p] => 0
            [post_parent] => 
            [subpost] => 
            [subpost_id] => 
            [attachment] => 
            [attachment_id] => 0
            [name] => 
            [static] => 
            [pagename] => 
            [page_id] => 0
            [second] => 
            [minute] => 
            [hour] => 
            [day] => 0
            [monthnum] => 0
            [year] => 0
            [w] => 0
            [category_name] => 
            [tag] => 
            [cat] => 
            [tag_id] => 
            [author] => 
            [author_name] => 
            [feed] => 
            [tb] => 
            [meta_value] => 
            [preview] => 
            [s] => 
            [sentence] => 
            [title] => 
            [fields] => 
            [menu_order] => 
            [embed] => 
            [category__in] => Array
                (
                )

            [category__not_in] => Array
                (
                )

            [category__and] => Array
                (
                )

            [post__in] => Array
                (
                )

            [post_name__in] => Array
                (
                )

            [tag__in] => Array
                (
                )

            [tag__not_in] => Array
                (
                )

            [tag__and] => Array
                (
                )

            [tag_slug__in] => Array
                (
                )

            [tag_slug__and] => Array
                (
                )

            [post_parent__in] => Array
                (
                )

            [post_parent__not_in] => Array
                (
                )

            [author__in] => Array
                (
                )

            [author__not_in] => Array
                (
                )

            [cache_results] => 1
            [update_post_term_cache] => 1
            [lazy_load_term_meta] => 1
            [update_post_meta_cache] => 1
            [nopaging] => 1
            [comments_per_page] => 50
            [no_found_rows] => 
        )

    [tax_query] => WP_Tax_Query Object
        (
            [queries] => Array
                (
                )

            [relation] => AND
            [table_aliases:protected] => Array
                (
                )

            [queried_terms] => Array
                (
                )

            [primary_table] => ahoywp_posts
            [primary_id_column] => ID
        )

    [meta_query] => WP_Meta_Query Object
        (
            [queries] => Array
                (
                    [0] => Array
                        (
                            [key] => wpcf-start-date-and-time
                        )

                    [1] => Array
                        (
                            [0] => Array
                                (
                                    [key] => approved-agencies-trip-level
                                    [value] => 3
                                    [type] => CHAR
                                    [compare] => =
                                )

                            [relation] => OR
                        )

                    [relation] => AND
                )

            [relation] => AND
            [meta_table] => ahoywp_postmeta
            [meta_id_column] => post_id
            [primary_table] => ahoywp_posts
            [primary_id_column] => ID
            [table_aliases:protected] => Array
                (
                    [0] => ahoywp_postmeta
                    [1] => mt1
                )

            [clauses:protected] => Array
                (
                    [ahoywp_postmeta] => Array
                        (
                            [key] => wpcf-start-date-and-time
                            [compare] => =
                            [compare_key] => =
                            [alias] => ahoywp_postmeta
                            [cast] => CHAR
                        )

                    [mt1] => Array
                        (
                            [key] => approved-agencies-trip-level
                            [value] => 3
                            [type] => CHAR
                            [compare] => =
                            [compare_key] => =
                            [alias] => mt1
                            [cast] => CHAR
                        )

                )

            [has_or_relation:protected] => 
        )

    [date_query] => 
    [request] => SELECT   ahoywp_posts.* FROM ahoywp_posts  INNER JOIN ahoywp_postmeta ON ( ahoywp_posts.ID = ahoywp_postmeta.post_id )  INNER JOIN ahoywp_postmeta AS mt1 ON ( ahoywp_posts.ID = mt1.post_id ) WHERE 1=1  AND ahoywp_posts.ID NOT IN (26) AND ( 
  ahoywp_postmeta.meta_key = 'wpcf-start-date-and-time' 
  AND 
  ( 
    ( mt1.meta_key = 'approved-agencies-trip-level' AND mt1.meta_value = '3' )
  )
) AND ahoywp_posts.post_type = 'trips' AND ((ahoywp_posts.post_status = 'publish' OR ahoywp_posts.post_status = 'private')) GROUP BY ahoywp_posts.ID ORDER BY ahoywp_postmeta.meta_value+0 ASC 
    [posts] => Array
        (
        )

    [post_count] => 0
    [current_post] => -1
    [in_the_loop] => 
    [comment_count] => 0
    [current_comment] => -1
    [found_posts] => 0
    [max_num_pages] => 0
    [max_num_comment_pages] => 0
    [is_single] => 
    [is_preview] => 
    [is_page] => 
    [is_archive] => 
    [is_date] => 
    [is_year] => 
    [is_month] => 
    [is_day] => 
    [is_time] => 
    [is_author] => 
    [is_category] => 
    [is_tag] => 
    [is_tax] => 
    [is_search] => 
    [is_feed] => 
    [is_comment_feed] => 
    [is_trackback] => 
    [is_home] => 1
    [is_privacy_policy] => 
    [is_404] => 
    [is_embed] => 
    [is_paged] => 
    [is_admin] => 
    [is_attachment] => 
    [is_singular] => 
    [is_robots] => 
    [is_posts_page] => 
    [is_post_type_archive] => 
    [query_vars_hash:WP_Query:private] => 9f47952fd64ed47134cbe1d2f3f28eff
    [query_vars_changed:WP_Query:private] => 
    [thumbnails_cached] => 
    [stopwords:WP_Query:private] => 
    [compat_fields:WP_Query:private] => Array
        (
            [0] => query_vars_hash
            [1] => query_vars_changed
        )

    [compat_methods:WP_Query:private] => Array
        (
            [0] => init_query_flags
            [1] => parse_tax_query
        )

)

Please can you advise on what the issue may be?

#1257407

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

Thank you for getting in touch.

I suspect the issue here is that you didn't add your shortcode name to the view 3rd party shortcode arguments. You can add it by going to Toolset -> Settings -> Frontend -> 3rd party shortcode arguments.

Thanks,
Shane

#1257435

Hi Shane,

It's already registered here, any other ideas what the issue may be?

Thanks

#1257437

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

Could you add this to your view and let me know what is returned?

[wpv-attribute name="storeid"]

Let me know what value is returned if its the correct one that you expect.

Thanks,
Shane

#1257445

When placed in the view it returns all posts without the required filter applied, so it is not working.

I also placed [wpv-attribute name="storeid"] in the page text to test it but it doesn't return any value.

#1257447

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

This would mean the value isn't being passed into the view.

I'm assuming your custom shortcode does return a value ?

Would you mind allowing me to have admin access to this site to check this out for you ?

The private fields have been enabled for your next response.

Thanks,
Shane

#1257529

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jon,

This should be working now.

All i did was to remove and re-add the filter and it worked fine.

Thanks,
Shane

#1257543

Thank you for your time Shane, I see it working now!