• Resolved vickygr89

    (@vickygr89)


    Hello,
    I am using your plugin on a new website we are working on. I have several Custom Posts Types name “Tax Sales”, that we can set the UM Restriction for login and logout users.
    I am trying to via a cron job that runs every hour check all tax sales and if the tax sale date (custom field )is older than now, I want to make all those past tax sales restricted to only login users.
    Is there a hook or filter I can use to change the Ultimate Member Restriction for each post?
    This is the code I have so far.

    // run cron jobs to change posts to private when tax sale date has passed
    add_action( 'past_results_private', 'past_results_private_now' );
    function past_results_private_now() {
        $args = array(
           'post_type' => 'tax-sales',
           'meta_key' => 'tax-sale-date',
           'meta_value' => date("F j, Y, g:i a"),
          'meta_compare' => '<',
       );
       $post_query = new WP_Query($args);
    
       if($post_query->have_posts() ) {
          while($post_query->have_posts() ) {
            $post_query->the_post();
               ///// CHANGE THE ULTIMATE MEMBER RESTRICTION TO LOGIN USERS ONLY
         }
           }
    }

    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @vickygr89

    I suggest that you create a post/page with the content restriction that you can copy for the tax-sales custom post type.

    Here’s an example code:

    add_action( 'past_results_private', 'past_results_private_now' );
    function past_results_private_now() {
        $args = array(
           'post_type' => 'tax-sales',
           'meta_key' => 'tax-sale-date',
           'meta_value' => date("F j, Y, g:i a"),
          'meta_compare' => '<',
       );
       $post_query = new WP_Query($args);
    
       if($post_query->have_posts() ) {
          while($post_query->have_posts() ) {
            $post_query->the_post();
    
              $copy_from_page_id = 123; // copy settings from this page
             $copy_content_restriction = get_post_meta( $copy_from_page_id,"um_content_restriction", true );
              update_post_meta( get_the_ID() ?, "um_content_restriction", $copy_content_restriction );
    
        ?}
      ?}
    }
    
    

    The above code will copy the content restriction from a page with ID 123. It will save the content restriction to the tax-sales custom post type.

    Thread Starter vickygr89

    (@vickygr89)

    Thanks so much for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change the Ultimate Member Restriction via functions.php’ is closed to new replies.