I'm trying to use [wpv-items-count] to get the filtered count of posts in a CPT based upon custom field vehicle-location but nothing seems to work. I think the problem might be that this custom field is related to another CPT? How can I make this work?
Hi Larry,
Thank you for waiting.
I see some major differences between settings of the view "Garage Count EP2" that is showing the count for "EP2" and the view "Garage Count EP1" that should be showing the count for the "EP1".
Garage Count EP2:
hidden link
Garage Count EP1:
hidden link
Is this difference in post type selection and the query filter section on purpose?
regards,
Waqar
Yes, I need to convert those to vehicle location. So they will all likely stop working.
Thanks for confirming.
I understand that the "Vehicle Location" field consists of options programmatically generated from the posts in the "TMNA Locations" post type.
In this case, this field will contain the post ID of the selected "TMNA Locations" post.
Considering the example of view "Garage Count EP1", if you need the list of posts where the "Vehicle Location" field has the selected option "Plano Parking Lot EP1 Level 1" TMNA Locations post ( /wp-admin/post.php?post=4986&action=edit ), you'll pass its ID: "4986" in the query filter section.
( screenshot: hidden link )
You can repeat the same for other views, by just changing the ID of the target TMNA Locations post.
Tip: You don't need separate views for showing the counts of different garages.
You can keep just one view for this purpose and set the query filter to get the target TMNA Locations post's ID, through view's shortcode attribute, for example, 'post'.
( screenshot: hidden link )
The shortcode for the view would change from:
{!{wpv-view name='garage-count-ep1' cached='off'}!}
To:
{!{wpv-view name='garage-count-ep1' cached='off' post='4986'}!}
Likewise, you can keep adding same view's shortcode for the other garages but changing the target TMNA Locations post's ID.
(can we make those items private please or remove any internal refs from above?)
If I need to combine multiple ids in the filter how can I do that? For example, there are multiple levels for EP1 (level 0, level 1, level 2, etc...)
Thanks
I've removed the reference to your website's domain from the messages in this thread. Please let me know if you'd like any other information to be removed/retracted.
If you'd like to get the count from the multiple post IDs, you'll need a custom shortcode, for example:
add_shortcode('get_sum_views_garage_count', 'get_sum_views_garage_count_fn');
function get_sum_views_garage_count_fn($atts) {
$a = shortcode_atts( array(
'id' => '',
), $atts );
$count = 0;
if ($a['id']) {
$id_array = explode(',', $a['id']);
foreach ($id_array as $id) {
$view_output = trim(do_shortcode('[wpv-view name="garage-count-ep1" post="'.$id.'"]'));
if($view_output > 0) {
$count = $count + $view_output;
}
}
}
return $count;
}
On the front-end, you can use this new custom shortcode like this, with the target IDs passed in the shortcode attribute:
[get_sum_views_garage_count id="4986,4987,4988"]
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
When I insert the shortcode I get 0. Shouldn't the post ID's be for the views not the posts? I'm a bit confused of what I'm totaling.
Referring to the tip shared at the end of my earlier message ( ref: https://toolset.com/forums/topic/the-count-is-not-showing-through-wpv-items-count-shortcode/#post-1765083 ), the custom shortcode solution from my last message assumes that you'll be using a single view, to get a count of any garage, by changing the post attribute.
For a case where you just need the count of one garage location:
{!{wpv-view name='garage-count-ep1' cached='off' post='4986'}!}
For a case where you need the count from more than one garage location:
[get_sum_views_garage_count id="4986,4987,4988"]
Note: The admin access no longer seems to work. In case you're still facing some difficulty in using this, please share the admin access details again and also the link to a page where you have tested this.
I've set your next reply as private.
I've created a test page to explain what I mean by using a single view to show count from any garage location and even for showing the sum from multiple locations:
Page: Test page from waqar:
yourwebsite.com/test-page-from-waqar/
Please note how this page is using only 1 View, "View to get the garage count" for all the different garage locations.
Important note: I've added the code for the custom shortcode through the Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) and it is resulting in an error, possibly because it might already exist in the theme's "functions.php" file
You can remove all the code below the line "// Put the code of your snippet below this comment.", in the file named "temp.php" from the folder "wp-content/toolset-customizations/" and it will be fixed.
As for the custom shortcode in the theme's "functions.php" file, you can update this new view's slug in it:
add_shortcode('get_sum_views_garage_count-ep1', 'get_sum_views_garage_count_fn');
function get_sum_views_garage_count_fn($atts) {
$a = shortcode_atts( array(
'id' => '',
), $atts );
$count = 0;
if ($a['id']) {
$id_array = explode(',', $a['id']);
foreach ($id_array as $id) {
$view_output = trim(do_shortcode('[wpv-view name="view-to-get-the-garage-count" post="'.$id.'"]'));
if($view_output > 0) {
$count = $count + $view_output;
}
}
}
return $count;
}
yes, I understood this part of it. But how do I add all of those 'ep1 level* together into one total? so level1 + level2 + level3 + level 4 + level 5? Or is that not possible?
To get the count of more than 1 garage locations, you'll be able to use the newly registered custom shortcode, like this:
[get_sum_views_garage_count id="4985,4986,4987,4988,4989,4990"]
Please check the back-end and the front-end of the test page that I've created and this will become more clear.
( Page: Test page from waqar )
My issue is resolved now. Thank you!
One more questions Waqar, do you mind turning on private please? Thanks