Okay, lol I made it SOOO far with this route without asking for help again but I got stuck. It was coming along beautifully.
I logged in to that site and checked it out, I think the only way it seems to work is if you know the recipients the CC & BCC ends up working, but to do it by a user ID from a generic field doesn't appear to work out. So I am happy to stick with multiple recipient fields if I get past a couple hurdles.
There were a few other elements to this where I had to make additional fields for each recipient, so 10 recipients = 10 extra fields across the board, no big deal, I got that semi-working, to something I know I can elaborate on.
Then I realized after all that, when it comes to the Views, showing a listing of all messages, that I cannot use query filters in the search & pagination area along with the query required in the top query section.
Specifically, because I cannot use the appropriate AND / OR configuration with the recipients and the custom field types filters matching a URL param (ie 'buildingname' )
So I need to show all results if X =( ( recipient1 or recipient2 or recipient3 or recipient 4.... ) AND ( buildingname LIKE urlparam ) )
But with the GUI I can only query like:
(recipient1 = x) OR (recipient2 = x) OR (recipient3 = x) OR (recipient4 = x) OR (buildingname LIKE urlparam )
If I omit the recipients in the query, the filters work beautifully, so I thought of showing only matching posts using conditional output but this was too slow and causing the website to timeout. Too heavy on the database I assume.
Bottom line is I can continue with this if I can inject a few other conditions to the query.
I have combed your documentation and forum and the best idea that seems to work is if I create a custom query in the functions.php
I have pieced together one that successfully limits the query to only show the author's own posts and figured it would adaptable to change 'author' to the 10 recipient fields.
Example with author:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_author' );
function prefix_show_only_current_author( $query_args ) {
if( $view_id == 1234 ) {
global $current_user;
$testuser = '240';
$types = (array) $query_args['post_type'];
print_r($query_args);
if ( !is_admin() && in_array( 'quotes', $types ) ) {
$query_args['author'] = empty( $current_user->ID ) ? -1 : $testuser;
}
return $query_args;
}
}
My failed attempts: ( Syntax obviously wrong I am not a coder, but hopefully you get what I am after )
add_filter( 'wpv_filter_query', 'prefix_show_only_current_author' );
function prefix_show_only_current_author( $query_args ) {
if( $view_id == 1234 ) {
global $current_user;
$testuser1 = '240'; //will make these dynamic later once these fields match
$testuser2 = '241';
$testuser3 = '242';
$types = (array) $query_args['post_type'];
print_r($query_args);
if ( !is_admin() && in_array( 'quotes', $types ) ) {
$query_args['wpcf-recipient1'] = empty( $current_user->ID ) ? -1 : $testuser1;
$query_args['wpcf-recipient2'] = empty( $current_user->ID ) ? -1 : $testuser2;
$query_args['wpcf-recipient3'] = empty( $current_user->ID ) ? -1 : $testuser3;
}
return $query_args;
}
}
I feel like I am close but have been spinning my wheels for days and would greatly appreciate any guidance.
Thank you