Skip Navigation

[Resolved] Get no posts when the none of the ids are passed in the view.

This support ticket is created 4 years, 1 month 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by puneetS-3 4 years, 1 month ago.

Assisted by: Beda.

Author
Posts
#1542821

I am trying to show favourite posts for a user. I am using hidden link to add a fav post to the user. I was able to set the view that filter through the ids passed for the current logged in user, but when none of the posts is marked fav, "" is passed into the view and all of the posts that are on the website are shown?

How can I show nothing when when no id is passed so that I can write no posts added to fav. Attaching the filter for my view. hidden link

#1542917

If you somehow managed to pass the value of "favourites" to the View ShortCode attribute "Ids", then you can also check on that value with an HTML conditional.

I assume you have some ShortCode or function that helps you pass the favourites to the IDs attribute, yes?
If so, please try to register that ShortCode in Toolset > Settings > Front End content > third party shortcode arguments, and then you can try to use it like so in an HTML conditional:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/

[wpv-conditional if="( '[YOUR_SHORTCODE_RETURNING_IDs]' eq '' )"]NO IDs are passed, so, do NOT display the view at all[/wpv-conditional]
[wpv-conditional if="( '[YOUR_SHORTCODE_RETURNING_IDs]' ne '' )"]IDs are indeed passed, so, DO display the view[/wpv-conditional]

Does this help?

If not, I will need to know how precisely you get that value (Ids), so we can check how to determine if there are some ids returned or not.

#1543053

Hey Beda,

As a result of the above solution, I am able to display all the favorite posts for a user or No post (when there is no favorite marked by user).
In my case, I have two Custom Post Types named as 'A' and 'B'. I want to display the favorite posts of 'A' and 'B' on a separate pages.
By using the given below Shortcode I am getting all the id's of Favorited posts. I want to filter the id's for particular Custom post type.
Suppose if user marked two posts as favorite of post type 'A' and one post of post type 'B' and I created a page [named as "Display Favorite Posts"] where I am displaying all Favorited posts of 'A' , then what is expected is to get id's of only that two post on Display Favorite Posts page.
But I'm getting all three id's there.

I tried to change the value of $filters attribute to the name of that particular custom post type. But it doesn't work.

function custom_favorites_list_thumbnail()
{
  $fav = get_user_favorites($user_id = null, $site_id = null, $filters = null);
  if($fav){
  $ids = implode(', ', $fav);
  }
  else {
    $ids = "";
  }
  return $ids;
}
add_shortcode('favorite_post_id', 'custom_favorites_list_thumbnail');
#1543055

This is a question that you could direct to the makers of that plugin since feature and data are created and stored by that plugin.
get_user_favorites() method used here is clearly an API of the plugin you use, not Toolset.

#1543111

Okay.
Thank you!

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