Guess I was just confused. I understand now, you need the top shortcode above "Latest" to work. Let me take another look.
Hey Christian,
Yeah correct, sorry! I know the code on the page was a little confusing it was because I was testing different things to see what works.
Yeah it's the top shortcode that I am trying to get working but if you don't hard code the user ID it doesn't work.
Well I think we simply exceeded the number of nested attributes. I put together a code snippet using the wpv_filter_query API to add the current User's ID automatically. I added that to a new Custom Code snippet in Toolset > Settings, called "Add current User ID to filter for View 96430 - My Tracked Shows - Just IDs." Here's the code:
add_filter( 'wpv_filter_query', 'ts_add_current_user_id_filter',99,3 );
function ts_add_current_user_id_filter( $query_args,$views_settings, $view_id) {
global $current_user;
$view_ids = array( 96430 );
if( in_array( $view_id, $view_ids)) {
$args = array(
array(
'key' => 'wpcf-user-id-track-shows',
'value' => $current_user->ID,
'compare' => '=',
'type' => 'NUMERIC'
)
);
$query['meta_query'][]= $args;
}
return $query_args;
}
I removed the User ID field from the View's Query Filter, since it is now handled programmatically. I also removed the userid shortcode attribute, since that nested attribute was breaking the limits. Now I can see results more like I'd expect.
With this code, any time you use the View #96430, the current User's ID will be added to the filter like this. No extra shortcode attribute is required. Let me know if this doesn't solve the problem for you.
Hi Christian
Thanks for this, I think I understand what you have done here.
Although results still don't seem correct.
Logged in as User ID 1 sure the list is related to User ID 1. However any other ID and the list still stays the same?
Is it possible its just looking at the User ID that created the page and not the current User ID? Or is it caching since there is no variable in the Shortcode now?
No, it's definitely based on the current User and not the post author. What do you see when you check the list? I see two posts. One is a TV Show, the other is a User Show. Screenshot attached.
Also, which User Show(s) have User ID 1 in the User Data custom fields?
Yeah I see the exact same 2 posts which isn't correct.
The results should be user shows only.
As your account is ID 19 you should only be seeing 96521 as a result.
And 18 should only be seeing 30162. However both see the same results.
I have updated user shows in WordPress using admin columns pro so you can easily see what each user ID should see (screenshot attached).
Let me know your thoughts? Maybe something is wrong somewhere then if you are saying the results are not just User Shows?
Okay you're right, they are both TV Shows. I don't know how I had that confused yesterday. Let's go step by step on this page:
hidden link
This page contains one View, which is "My Tracked Shows":
hidden link
That View has a Query Filter that is supposed to respond to a shortcode attribute userid. However, no shortcode attribute is passed. Since that param is unset, no filtering is applied and the limit of 1 post means only the most recent post is returned. However, nothing about this one returned post is displayed. The template of this View is used to display information about other posts. So can you explain in more detail what's going on with this top-level View?
Hi Christian
I am pretty sure this top level view is redundant. The way I went around building it initially was different and I believe then this was used.
So I have gone ahead and put the code
[wpv-view name="my-tracked-shows-individual-tv-show-listing" showids="[wpv-view name='my-tracked-shows-just-ids']"]
straight into the page now instead and marked that view as redundant (left it existing for now just in case need to refer back to it).
So this should show a list of TV shows based on the User ID and the relevant User Show IDs. However it is not doing.
Hope that makes sense?
Yes, thanks, just wanted to make sure I wasn't misunderstanding something. Okay I looked again and saw an error in my custom code snippet that was preventing the custom field filter from working correctly. I made a variable name adjustment there and now I'm seeing more accurate results in the "just IDs" view, producing more accurate results in the main TV Show view. Code was:
$query['meta_query'][]= $args;
Now is:
$query_args['meta_query'][]= $args;
I temporarily adjusted the Futurama TV show to have an air date in the future, and set my user id 19 in the User Show item here: hidden link
The Futurama show began to appear in my results on the page, so that seems more accurate. However, I don't have another account to test with, can you check?
I think it is working now! 🙂
I have ran a few tests and will run a few more but I think it is solved. Thanks!