New Listing Status

This topic contains 6 replies, has 2 voices, and was last updated by  Stiofan O’Connor 7 years, 4 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #392745

    Shane Blevins
    Expired Member
    Post count: 25

    Hello,
    I run a geodirectory with multiple CPT that represent various categories. The directory is free for all, but I have two (similar) issues I could use help with. For most people I want the listings to goto draft form (which it does), however for certain organizations I would like them to have the ability to direct publish.

    Additionally on one directory I would like everyone to have the ability to publish immediately. I use the directory for a non-standard type use and hence have some unique challenges.

    Any information or suggestions would be a great help!
    Thanks

    #392750

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Shane,

    Are these paid or free listings or mixed?
    I don’t think there is a way to alter this per CPT, but is that what you are asking or are you asking per user?

    Please explain a bit more and i’ll be able to suggest the best action.

    Thanks,

    Stiofan

    #392752

    Shane Blevins
    Expired Member
    Post count: 25

    Sure… so to clarify both point.
    First all are free

    In one case I use it as a weather alert map..and I want everyone to be able to post automatically to that CPT without draft

    On the other I use it as a crime directory I want to allow police agencies the ability to post directly, but the normal people to goto draft.

    For the police issue I considered creating a package and only allowing aurthoized agencies the ability to sign up for it..to overcome that..I haven’t gotten that far.
    My current big challenge is how to make a single CPT have a default listing as published while the others remain draft…due to the time critical nature of weather emergencies

    #392757

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Ok i think this is what i would do…
    Set the default status to “Pending Review” and then add a hook on post_save that checks the conditions and sets the status publish only if met, example below (NOT TESTED):

    
    
    function _my_save_post_actions($post_id, $post, $update) {
        // if an update then bail.	
        if($update){ return;}
    
    	// a post type check
    	if ( isset($post->post_type) && $post->post_type=='gd_place' && $post->post_status!='publish') {
    		// unhook this function so it doesn't loop infinitely
    		remove_action( 'save_post', '_my_save_post_actions', 10 );
    
    		// we want to publish all gd_place listings
    		wp_update_post(array(
                        'ID'    =>  $post_id,
                        'post_status'   =>  'publish'
                    ));
    
    		// re-hook this function
    		add_action( 'save_post', '_my_save_post_actions',10, 3 );
    	}
    
            // a user check
            $current_user_id = get_current_user_id();
            $allowed_user_ids = array(1,5,10,20);// list of allowed user ids
    	if ( in_array( $current_user_id, $allowed_user_ids) && $post->post_status!='publish') {
    		// unhook this function so it doesn't loop infinitely
    		remove_action( 'save_post', '_my_save_post_actions', 10 );
    
    		// we want to publish all gd_place listings
    		wp_update_post(array(
                        'ID'    =>  $post_id,
                        'post_status'   =>  'publish'
                    ));
    
    		// re-hook this function
    		add_action( 'save_post', '_my_save_post_actions',10, 3 );
    	}
    
    }
    add_action( 'save_post', '_my_save_post_actions',10,3 );

    hopefully that example is enough to get you going 🙂

    Thanks,

    Stiofan

    #392764

    Shane Blevins
    Expired Member
    Post count: 25

    Stiofan, and WPGEO in general as always thank you for the excellent customer service!
    I’m not very familiar with the process of hooks, but will read up and I’m sure I can figure it out. For my clarity should this accomplish both points I was asking about or only one?

    #392776

    Shane Blevins
    Expired Member
    Post count: 25

    Just out of curiosity. .. do y’all do customization (like the above?) If so how would I go about getting a quote for it?

    #392841

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi Shane,

    We do not do customization, we will provide you examples of how our hooks/filters work but we won’t build your site for you. You can post in the forum jobs section or try hiring a developer elsewhere.

    The above example would do both things but you would need to replace the custom post type name and the user IDs with your specific requirements.

    Thanks,

    Stiofan

Viewing 7 posts - 1 through 7 (of 7 total)

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

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount