This support ticket is created 6 years, 3 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.
Author of all posts (post type post) is admin. admin want access to view post only to those users who are allowed and stored in custom post allowed users.
in allowed users custom post there are two fields user id and post id
in user id field there and user id of users and post id field there are post id
ex: user id: 3 post id :160
if user 3(user id) is logged he wand to try to view post id 160 (posted by admin) then i want to query if user is allowed to view post which id is 160 by querying user id of current logged in user and current post user is trying to view by querying custom post allowed users.
I tried to achieve this by passing parameter in view "Allowed Posts-Check if user subscribed to post"
Select items with field:
user id is a string equal to VIEW_PARAM(userid)
AND
post id is a string equal to VIEW_PARAM(postid)
then i put following in post layout :
[wpv-conditional if="( '[wpv-view name="allowed-posts-check-if-user-subscribed-to-post" userid="[wpv-user field="ID"]" postid="[wpv-post-id]"]' eq '0' )"]user not subscribed to this post[/wpv-conditional]
Your conditional shortcode isn't working because the output of a View (from the wpv-view shortcode) contains a wrapper div and not just the View results (see screenshot), so testing for eq '0' is meaningless.
A Views update later this month will add the possibility to output a "raw" View without the wrapper, making such tests more straightforward.
If you need something like that now, you can add the following code to your theme's functions.php file to strip away the wrapper, and then your conditional shortcode can test for whatever content you include between the wpv-no-items-found shortcodes of your View output.
Sorry but I could not understand what you are asking.
I inserted code in functions.php but it give no output.
I removed all extra code.
[wpv-conditional if="( '[wpv-view name="allowed-posts-check-if-user-subscribed-to-post" userid="[wpv-user field="ID"]"
postid="[wpv-post-id]"]' eq '0' )"]user not subscribed to this post[/wpv-conditional]
link of post user not subscribed is : hidden link
There should be a message : user not subscribed to this post
Sorry if it wasn't clear, but the code I supplied, you need to edit the ID of the View that you need to "clean" the output of.
If the View has some posts it will output what is between the wpv-items-found shortcodes (in the Loop Output section of the View) and if the View contains no posts it will output what is between the wpv-no-items-found shortcodes.
Your wpv-conditional shortcode is testing if the View output eq '0', which it won't.
Or try outputting the View without the wpv-conditional shortcode so that you can see in the page source exactly what is output for it when a user doesn't have permission to see the post.
It might be easier to edit your View output to simplify what is included in the wpv-no-items-found section, which by default looks like this
I want to clear again basically i am querying custom post "allowed users"
which have two fields(meta keys) user id and post id.
what i am trying to do:
What i am trying to do:
if current logged in user visit post url to view post i want to check current logged in user and current post in allowed users custom post something like this
if logged-in-user and current post found in custom post "allowed user" . if record found then allow otherwise restrict some content of post. may be this can be achieved with some custom code counting custom post with current-logged-in-user and current-post>0 ithen allow else restrict some content
I took a closer look at your condition and see that you were mixing up the double and single quotes, which I've tried to fix, but it's still not working, so much so that the debug="true" attribute doesn't even work.
It seems like the expression is too complex.
I would instead try writing a custom function to do the same thing instead of the View that can be used in the wpv-conditional shortcode.
I added the following function to your Code Snippets: