I have created a frontend form that allows logged in users to submit content to my wordpress site. The form allows them to submit to a custom content type. I would like be able to change the status of the submitted post depending on that users previous submissions. So if they already have 1 or more published posts then the submission goes to publish - if they don't then it goes to pending.
I know the argument that I need to change: 'post_status' => 'publish' - I just don't really have a clue how to start on the logic - let alone what the most efficient way of achieving it will be...?
first, set post_status as a PHP variable that is set by a function, and hard coded returned from within the function.
Then, refactor the function to do a separate WP_Query to find the count of published custom post types with the current userid as author. If >=1, return 'publish' else return 'draft'
Related
I have two custom post types ("affiliate_codes" & "affiliate_tracker") that share a custom field ("affiliate_code"). In "affiliate_codes" I manage a master list of affiliate accounts (ie Affiliate Code, WP User, Percentage). In "affiliate_tracker", I have a form that adds new posts to the CPT passing fields such as Affiliate Code, Purchase Amt, etc.
I'm trying to create a report that is essentially a query that combines data from both of these CPTs, using the affiliate_code custom field to join the two CPTs together for the query.
A user could have more than one affiliate_code associated, so it would need to use the user ID passed in to grab all affiliate_codes associated to that user ID in 'affiliate_codes' CPT, and then retrieve all posts from 'affiliate_tracker' CPT that includes any of the codes associated to the user.
Is there a way to Join two custom post types as part of one query?
I initially tried to do this by nesting a second query within the main query.
Query 1 - pulling all posts from affiliate_tracker CPT and looping through.
Query 2 (nested inside the loop above) - uses affiliate code field to retrieve User from affiliate_code CPT
This works fine when I want to return all posts in affiliate_tracker. I also need to be able to filter the posts returned to only those associated with a specific user which is where I am struggling. Ideally I could have one query that combines the two CPTs by connecting posts via the shared 'affiliate_code' field and then can pull all posts from affiliate_tracker that have a code that is associated to a specific user. Not sure if this is possible.
Of course m8 , u can do it easily.
$args = array(
'post_type' => [ 'affiliate_codes', 'affiliate_tracker' ],
'post_status' => 'publish',
);
$query = new WP_Query( $args );
Above query gives you the all posts of these post types , now using following link you can filter them based on meta values based on your needs
Wordpress meta query parmeters
I am currently using a code similar to what I need, from LoicTheAztec ( who should really be called "DaMan"). That code triggers Woo to send an email to a custom email address when order status is changed to "Processing". Without that code, a notification email only goes to the customer.
For my case I want to send a notification to both the customer, and the store owner. I was able to tweak previous code to do this - but the result was that both the customer and owner get the same email ( as in, they are both copied on exact same notice from Woo).
Here is what I am currently using in my functions.php:
// notify when order status set to processing
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'processing_order_replacement_email_recipient', 10, 2 );
function processing_order_replacement_email_recipient( $recipient, $order ) {
// Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
$recipient .= ',example#owneremail.com';
return $recipient;
}
How could I trigger this so that the customer gets their copy, and the owner gets her copy separately? Also typically the stock emails generated by WOO have slightly different text versions between customer and store owner.
If what I am asking can't be done, I'll stick with what I have. Just wondering if there is a cleaner way to achieve it. Thanks in advance for any assistance!
Intro info:
I have a Custom Post Type (CPT) called Service.
I am already connecting users to this CPT using the plug-in 'Posts 2 Posts', this is a many to many relation, and these users connected to the CPT represent the 'team' of said Service.
Alright so here's the headscratcher:
Now I want to create a custom field in the CPT Service, which will be the Director of the Service. Say a field called 'Director' in which the value is a User.
Ideally, the value of the field Director is a User, not a string representing the user name or anything like that.
I have no idea how to start tackling this issue and some brightness on the subject would be strongly appreciated.
Thank you!
save it as post_meta. e.g if you have the user email:
$user = get_user_by( 'email');
update_post_meta($serviceid, '_director', $user->ID);
If you are setting this up in the admin section you can add a meta box and attach a action to save_posts to save a html field where you select a user. Google add_meta_box, there are a load of tutorials on this.
I have noticed that the list of users generated by users.php in my dashboard doesn't take into account custom post types when it displays the number of posts by each user.
So even if a user has 20 posts of a custom post type, it will still show '0' next to their name.
Does anyone know how to resolve this and add custom post types to this number?
For anyone else looking to achieve the same, I managed to resolve it using this solution...
function my_manage_users_columns($columns) {
$columns['post_type_count'] = __( 'Books', 'textdomain' );
return $columns;
}
add_filter('manage_users_columns', 'my_manage_users_columns');
With 'Books' being the name of the custom field
Playing around with the subscriptions module; i have some troubles getting it to send the right notification for right subscription.
Here's the situation :
I have a content-type of type 'work'; it has a cck-taxonomy field; when creating the content users choses one category in which his 'work' fulfills.
In user profil, under Categories (user/3/subscriptions/taxa) I choose two categories, lets say 'house work' and 'car work'.
When creating a new 'work' content I do not get the notification.
But, when manually select 'content-type' in user's profile of type 'work' I get the notification e-mail but independant to which 'category' i had chosen.
This is quite annoying since I only want the user to receive his notifications upon the taxonomy he has chosen, not for every new content of type 'work'.
Am I missing something obvious here ?
i have made it working fine for a taxonomy using the settings provided by the module. Concerning the rights i only allowed 'Subscribe to taxonomy terms '