Alex Howes
Forum Replies Created
-
AuthorPosts
-
Thanks Kiran, it’s still not working though
Since the other parts of the code were working fine when the first “if” statement was working, it must be a problem with $post and how I’m trying to access the post type. I’ve put this bit in because I only want the user role to be changed when a listing of a certain CPT (CV) is listed.
add_filter('wp_insert_post_empty_content', 'change_user_role_when_submit_cv'); function change_user_role_when_submit_cv( $data ) { global $post; if ($post['post_type'] =='gd_cv') { $current_user = wp_get_current_user(); $current_user_roles = $current_user->roles; if (in_array('um_worker', $current_user_roles)){ $current_user->set_role( 'worker_has_cv' ); } } return $data; }
Thanks for pointing that out Guust, that’s a nice neat solution. I’ve set it to “Looking for Job Types” to tie in with my job CPT.
Alex
Hi,
I see in my message before I used the wrong quotes, but in my code they’re the right ones. Something else must be the problem.
Alex
Thanks! Unfortunately I noticed a mistake. The first if statement should be:
if ($post->post_type ==’gd_cv’)
Now it isn’t working and I can’t work out why. Any ideas? Does $post here not refer to the listing form?
I’ve now added a category to CV, and since there is only one would like to hide the category select option in the add listing form and assign that category automatically. I have written the following code based on this https://wpgeodirectory.com/support/topic/autofill-category/
jQuery(document).ready(function(){
if(location.pathname == “/add-listing/”)
{
$price_id = jQuery(‘[name=”package_id”]:checked’).val();if($price_id == 5)
{
jQuery(‘#gd_placecategory.chosen_select’).val(’82’).change();
setTimeout(function()
{
jQuery(‘input[name = post_default_category][value = 82]’).attr(“checked”, “checked”);
}, 2000);}
}
});
It isn’t working 🙁 Does it need to be modified to specify which CPT I’m interested in? (Though I thought this was done by the “price_id” bit). I’ve tried changing #gd_placecategory to #gd_cvcategory but this doesn’t solve the problem.
I’ve removed the “/” from my multiselect field.
Do I have to have CV categories? I’ve disabled physical location for that CPT.
What do you mean about setting the description to zero characters in the price package?
The error appears after you press “Review Farm Listing” on the next page. It appears in between the CV title and the tabs. E.g. I created a CV called “Test 5” and the preview page looks like this (see attached):
This reply has been marked as private.I’ve now solved this (sorry!)
The default search range was being set to 40, and I had set the maximum search range to 30 (in GD -> farm settings -> advance search). Perhaps there should be something to prevent this happening?
Alex
Thanks Kiran and Alex. I’ve now got a snippet working which changes user role when a worker submits a listing (in my case a CV listing). This then lets me easily hide content from the new role, such as the page to add a new listing. I’ll post my code here in case anybody else is interested in this.
add_filter(‘wp_insert_post_empty_content’, ‘change_user_role_when_submit_cv’);
function change_user_role_when_submit_cv( $data ) {
global $post;
$post_type = get_post_type( $post->ID );if ($post_type = ‘gd_cv’) {
$current_user = wp_get_current_user();
$current_user_roles = $current_user->roles;if (in_array(‘um_worker’, $current_user_roles)){
$current_user->set_role( ‘worker_has_cv’ );
}
}
return $data;
}Great, thanks! 🙂 I’ll have a look through that and see what I can do.
I’m interested in changing the user role when a user submits a listing, since I think that could be a simple solution. Do you know what geodirectory function/ action/ filter is relevant to hook into that?
I.e. I want to say “when a user submits a listing, change user role.” I know how to do the latter but not the former. Any tips?
Hmm. I realise users can create multiple accounts but that takes more effort on their part which I hope will be a discouragement!
I was thinking about the problem and wondering whether it’d be possible to create a user role for users who have submitted a listing, and assign users to this role when they submit a listing. It’d be pretty straight forward then to hide content from this role, e.g. the add listing page.
This would require some customization but perhaps only a small snippet, i.e. to hook into the listing submission action and then to reassign the user’s role. I think I can reassign the role using the WP_User class, but what would be the correct action/ filter to hook into the listing submission action (of a certain CPT)?
I understand that your support doesn’t cover customization but I’d be really grateful if you could point me in the right direction.
Cool, thanks for the link!
In the end I decided to post the information as a widget instead, and use a third party plugin to only display it for certain user roles. I looked at using the code in the link but couldn’t find a capability that distinguished the user roles from each other, and thought it’d be more visible as a widget anyway 🙂
Great, thanks! 🙂 It’s all working now.
Is it possible to add something to my code to make the new tab visible only to logged in users of a certain role?
-
AuthorPosts