Skip Navigation

[Resolved] Only display posts from users whose email matches an email field

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

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

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 15 replies, has 2 voices.

Last updated by gavinS 8 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#353844

I have a type called 'Leads'. Within this type I have an email field called 'Assigned to', and another field called 'Job reference or reason'.

I now want to create a view which only shows Leads where the 'assigned to' field matches the current users email address. I would also like to only display the leads for this user if the 'job reference or reason' field is null.

#353923

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Using [wpv-current-user info="email"] you will be able grab the current user email address.
=> https://toolset.com/documentation/views-shortcodes/#wpv-current-user

Then you should check with [wpv-current-user info="email"] value with your custom field value. Could you please try to use Views conditional statement:

For example:

 [wpv-conditional if="( $(wpcf-email) eq '[wpv-current-user info='email']' )"]
Whatever you want to display conditionally
[/wpv-conditional]

More information:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#354251
Open Leads.png

Hi Minesh

Thanks for that.

I have got it to work, however the bullet points for items in the view which are not being shown are still being displayed. Any idea how to remove those?

#354348

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can use CSS to hide the bullets.

For example:

.Your-class ul{
     list-style:none;
}

Note: Replace .your-class with your ul container div's class name.

More reference:
=> http://stackoverflow.com/questions/8481474/how-do-i-hide-the-bullets-on-my-list-for-the-sidebar

#354468

Hi Minesh

Okay, I can hide the bullet points, but it is still 'displaying' the empty records. So If I change the number of records per page to 3, then I get a second page with nothing but empty records on it.

It's not so much that I want to hide the bullet points as I don't want it to 'see' the empty records.

#354487

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share screenshot of your Edit view page?

#354518
Leads output.png
Filters - leads.png
Edit view - leads.png

Hi Minesh

Which part of the page? I have enclosed a shot of the Loop Output and filters sections. Is that what you want?

I've also attached a shot of the output on the page. I have changed the pagination to be 3 per page, and as you can see it is bringing up the pagination controls, even though there are only 2 fields displayed. It was doing this even when I removed the bullet points with CSS.

#354524

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I think its better that you send me access details and link of the page where you have added your view.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#354539

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share link of the page where I can reproduce your issue and where you added following condition with which view:

[wpv-conditional if="( $(wpcf-email) eq '[wpv-current-user info='email']' )"]
Whatever you want to display conditionally
[/wpv-conditional]
#354806

Hi Minesh

I am displaying the view on the home page of top1.gammawebsolutions.co.za.

I didn't use the conditional for user emails as I thought it would be easier to debug without that as then you would need to create your own records. Instead I am just using the other conditional I want to use for this view, to only show records where the 'job reference or reason' field is null.

That would be this view:

hidden link

As you can see, I have set the number of items per page to be three. There are only 3 records which have a 'job reference or reason' field equal to null, and yet it is showing a second (empty) page.

Thanks

Gavin

#354920

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please send me FTP access details as I need to modify your functions.php file.

#355184

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Unfortunately FTP access details are not working at this end. Could you please re-send it to me again.

#355197

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now: hidden link

I've added following code to your functions.php file that is used to get fields with empty values for custom field 'wpcf-job-reference-or-reason'.

add_filter( 'posts_where' , 'posts_where' );
function posts_where( $where ) {
global $wpdb;

global $WP_Views;
 if($WP_Views->current_view == 149){
	 $where .= " And $wpdb->posts.ID NOT IN  (SELECT post_id FROM $wpdb->postmeta
												WHERE ($wpdb->postmeta.post_id = $wpdb->posts.ID)
												AND meta_key = 'wpcf-job-reference-or-reason'
											)";

}
		
	return $where;

}
#355233

Hi Minesh

Thanks. That seems to be working. I'm just trying to understand how it works.

I don't see that function being called from anywhere? Does it just automatically use that because of the view ID number you have set?

#355238

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It will automatically called as I've added filter.

add_filter( 'posts_where' , 'posts_where' );

And this filter will be applicable to this your view ID 149 specifically, so it will not affect other views you will create.

More Info:
https://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where

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