Geodirectory linked listings
This topic contains 15 replies, has 5 voices, and was last updated by Paolo 6 years, 10 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
May 12, 2018 at 10:06 am #430212
Hello,
Sorry for asking so many questions but thanks for your great support!
Two of my CPTs, jobs and farms, are linked (jobs are linked to farms). I want users to have to have a farm to be able to post a job. Is that possible?
Thanks 🙂
AlexMay 12, 2018 at 10:24 am #430214I am not sure I understand. Can you say a bit more?
Did you already share the link to your visitors to allow them to post a job?May 12, 2018 at 10:45 am #430217Sorry. My site is primarily a farm job site. There are two CPTs, jobs and farms, which are linked. Users with the role “employer” can claim farm listings, list farms, and post jobs.
Currently employers can post jobs whether or not they have a farm because the “Link Farm” option at the top of the add job form is optional.
However, I want to force all employers to link posted jobs to one of their farms, and not be able to post jobs if they don’t have a farm. I.e. there should be no jobs appearing that aren’t linked to a farm. Is it possible to do this?
May 12, 2018 at 10:45 am #430218If I understand correctly, there is no option for a user to have a listing in one CPT before they can post a listing in another CPT.
May 12, 2018 at 10:57 am #430219Ah ok, the two CPTs are linked in geodirectory. I was wondering because I understand the most common use of linked listings are “events” and “venues”- it might seem odd to have a venue without an event linked to it.
However, if this is not possible, I think what I can do is change the user’s role when they submit a farm listing, or when they claim a farm. I can do the former, but I’m not sure how to change the role when they claim a farm (when the claim is approved). Do you know if there’s a GD action or filter that would let me hook into this?
Thanks 🙂
May 12, 2018 at 11:12 am #430220Is there a way to force users to link a CPT on the add listing form (if the CPT is linked)? I.e. to make the “Link CPT” field non-optional?
May 12, 2018 at 3:53 pm #430237I’m sorry, but this would require a customization.
May 12, 2018 at 4:30 pm #430239Just to be clear, I’ve attached a screenshot and circled the field I would like to make required. Since it’s possible to make the other add listing form fields required, is it possible to make this one too? If it’s not simple, would you be able to point me in the right direction- the relevant action or filter I could use to write a snippet to do this?
Thanks 🙂
May 12, 2018 at 4:36 pm #430241It is not possible to make it mandatory. That is not a normal field of the add listing form.
I don’t think it is possible to do that with PHP, you can definitely do that with JavaScript.
You can find an example here: https://www.w3schools.com/js/js_validation.asp
May 12, 2018 at 4:42 pm #430242Thanks Paolo, I’ll take a look at that.
I’m currently also writing a snippet to change user role when they claim a listing and admin approves it. I’m hooking to the action geodir_claim_request_status_change, but currently the function isn’t even being called.
Am I correct in thinking that geodir_claim_request_status_change is called when a) a user claims a listing, b) admin approves the listing claim, and c) if a user deletes their listing claim, or is this incorrect?
May 12, 2018 at 6:03 pm #430247I’m not sure about it as well, I asked to the developers to double check and let you know.
Thanks
May 13, 2018 at 4:48 pm #430330Thanks, that’d be helpful
May 14, 2018 at 8:59 am #430428it is called on , approve, reject, undo, confirm
a different hook is used when a claim is deleteddo_action('geodir_claim_request_delete', $pid, $post_id);
Thanks,
Stiofan
May 14, 2018 at 4:43 pm #430524Thanks, I think my snippet wasn’t being called because the user claiming the listing wasn’t verifying by email, I was just approving the claim in the back end.
If anyone else is interested in doing this I’ve posted my code below.
add_action('geodir_claim_request_status_change', 'change_user_role_when_claim_farm', 10, 3); function change_user_role_when_claim_farm( $claim_id, $new_status, $old_status ) { $claim_info = geodir_claim_get_info( $claim_id ); if ($claim_info) { $post_id = (int)$claim_info->list_id; $claimed_post_type = get_post_type($post_id); $author_id = (int)$claim_info->user_id; $new_owner = get_userdata($author_id); $new_owner_roles = $new_owner->roles; if ($claimed_post_type == 'gd_farm') { if ($new_status == 1) { if (in_array('employer', $new_owner_roles)){ $new_owner->set_role( 'employer_has_farm' ); } } } } }
May 14, 2018 at 4:45 pm #430525Thanks Paolo for pointing out the JavaScript suggesting and posting that link. I’ve written some code and put it in the footer script code, and it’s working 🙂 In case anyone else wants to do this my code is:
<script type="text/javascript"> var submitjobForm = document.forms["propertyform"]; if (submitjobForm) { submitjobForm.addEventListener('submit', function(event){ var x = document.getElementById("geodir_link_cpt_business"); if (x) { if (x.value == "" || x.value == "No Business") { alert("Please select your farm"); event.preventDefault(); } } }, true); } </script>
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket