Geodirectory linked listings

This topic contains 15 replies, has 5 voices, and was last updated by  Paolo 6 years, 1 month ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #430212

    Alex Howes
    Expired Member
    Post count: 175

    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 🙂
    Alex

    #430214

    Alex Rollin
    Moderator
    Post count: 27815

    I 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?

    #430217

    Alex Howes
    Expired Member
    Post count: 175

    Sorry. 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?

    #430218

    Guust
    Moderator
    Post count: 29970

    If 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.

    #430219

    Alex Howes
    Expired Member
    Post count: 175

    Ah 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 🙂

    #430220

    Alex Howes
    Expired Member
    Post count: 175

    Is 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?

    #430237

    Paolo
    Site Admin
    Post count: 31206

    I’m sorry, but this would require a customization.

    #430239

    Alex Howes
    Expired Member
    Post count: 175

    Just 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 🙂

    #430241

    Paolo
    Site Admin
    Post count: 31206

    It 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

    #430242

    Alex Howes
    Expired Member
    Post count: 175

    Thanks 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?

    #430247

    Paolo
    Site Admin
    Post count: 31206

    I’m not sure about it as well, I asked to the developers to double check and let you know.

    Thanks

    #430330

    Alex Howes
    Expired Member
    Post count: 175

    Thanks, that’d be helpful

    #430428

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    it is called on , approve, reject, undo, confirm
    a different hook is used when a claim is deleted

    do_action('geodir_claim_request_delete', $pid, $post_id);

    Thanks,

    Stiofan

    #430524

    Alex Howes
    Expired Member
    Post count: 175

    Thanks, 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' );
    				}
    			}
    		}
    	}
    }
    #430525

    Alex Howes
    Expired Member
    Post count: 175

    Thanks 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>
Viewing 15 posts - 1 through 15 (of 16 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket