Forum Replies Created

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter eVersatile

    (@eversatile)

    Excellent.
    That code snippet did accomplish the task.
    Thank you for your help, and enjoy your day.

    Thread Starter eVersatile

    (@eversatile)

    I’ve tried modifying the sample codes, but I don’t think it’s quite what I’m looking for…
    I have opened a ticket ‘#38’ in the HelpDesk and attached 2 images, showing asample of what I’d like to export.
    It’s basically another the id of the field would be ‘order_fee_ine_items’ with class ‘fee’.

    Thread Starter eVersatile

    (@eversatile)

    Thank you. That did work.

    Thread Starter eVersatile

    (@eversatile)

    I’ve looked through the documents and tried your suggestion but still can not get it to work like I’m wanting.
    Here is a link to the page in question. https://bookpressed.com/pro_con/
    nder the ‘Levels’ filter, I wold like to change the order to ‘Beginner, Intermediate, Advanced’.

    Thread Starter eVersatile

    (@eversatile)

    I believe you are most likely correct, but I am having trouble on figuring out how to fix it.
    I added `<?php
    if(!isset($_SESSION)){
    session_start();
    echo session_id();
    }
    ?>` to check for the session ID when I reload the page.
    The session ID changes every time I reload. How can I keep the session going? Along with a new session created when a new post is created? I imagine the best way to go would be to create one session for each post and keep it on there for 30 days….

    Thread Starter eVersatile

    (@eversatile)

    I have put together the following code, though it is resetting everytime I reload the page.
    Do you know how I could prevent the timer from resetting?

    <?php
    session_start();
    $timestamp = time();
    $diff = 86400;
    
    $hld_diff = $diff;
    if(isset($_SESSION['ts'])) {
    	$slice = ($timestamp - $_SESSION['ts']);	
    	$diff = $diff - $slice;
    }
    
    if(!isset($_SESSION['ts']) || $diff > $hld_diff || $diff < 0) {
    	$diff = $hld_diff;
    	$_SESSION['ts'] = $timestamp;
    }
    
    $diff; //$diff holds seconds less than 3600 (1 hour);
    
    $hours = floor($diff / 3600) . ' : ';
    $diff = $diff % 3600;
    $minutes = floor($diff / 60) . ' : ';
    $diff = $diff % 60;
    $seconds = $diff;
    
    ?>
    <div id="strclock">Clock Here!</div>
    <script type="text/javascript">
     var hour = <?php echo floor($hours); ?>;
     var min = <?php echo floor($minutes); ?>;
     var sec = <?php echo floor($seconds); ?>
    
    function countdown() {
     if(sec <= 0 && min > 0) {
      sec = 59;
      min -= 1;
     }
     else if(min <= 0 && sec <= 0) {
      min = 0;
      sec = 0;
     }
     else {
      sec -= 1;
     }
     
     if(min <= 0 && hour > 0) {
      min = 59;
      hour -= 1;
     }
     
     var pat = /^[0-9]{1}$/;
     sec = (pat.test(sec) == true) ? '0'+sec : sec;
     min = (pat.test(min) == true) ? '0'+min : min;
     hour = (pat.test(hour) == true) ? '0'+hour : hour;
     
     document.getElementById('strclock').innerHTML = hour+":"+min+":"+sec;
     setTimeout("countdown()",1000);
     }
     countdown();
    </script>
    Thread Starter eVersatile

    (@eversatile)

    Thank you for the information.
    The timer does not have to be 100% accurate. Just a ‘post before this date’.
    I have already created an event to change the post from draft to ‘pending’ if they do not ‘publish’ by the end of that date.
    Though, I have not figured out a way to start a visual timer once the post is saved as a draft.

    Thread Starter eVersatile

    (@eversatile)

    I got it to work using this snippet

    add_action( 'comment_post', 'wpse_make_private_after_3_comments', 10, 2 );
    
    function wpse_make_private_after_3_comments( $comment_ID, $comment_approved ) {
        $comment = get_comment( $comment_ID );
        $post_ID = $comment->comment_post_ID;
        $comments = wp_count_comments( $post_ID );
    
        // You could also access approved, moderated, spam or trashed comments
        // from the return object of wp_count_comments().
    
        $comment_count = $comments->total_comments;
    
        // If we only have 1 or 2 comments, we'll bail early
        if ( $comment_count < 3 ) {
            return;
        }
    
        $post_data = array(
            'ID' => $post_ID,
            'post_status' => 'private'
        );
    
        wp_update_post( $post_data );
    
        // You might want to add a wp_redirect() here to 
        // so people don't automatically see a 404 page 
        // when the comment saving is complete since the page will be private.
    }
    Thread Starter eVersatile

    (@eversatile)

    I am still working on this..
    Now I have this code

    add_action( 'comment_post', 'wpse_make_private_after_3_comments', 10, 2 );
    
    function wpse_make_private_after_3_comments( $comment_ID, $comment_approved ) {
        $comment = get_comment( $comment_ID );
        $post_ID = $comment['comment_post_ID'];
        $comment_count = wp_count_comments( $post_ID );
    
        // If we only have 1 or 2 comments, we'll bail early
        if ( $comment_count < 3 ) {
            return;
        }
    
        $post_data = array(
            'ID' => $post_ID,
            'post_status' => 'private'
        );
    
        wp_update_post( $post_data );
    
        // You might want to add a wp_redirect() here to 
        // so people don't automatically see a 404 page 
        // when the comment saving is complete since the page will be private.
    }

    but after submitting a comment I get this error ‘Fatal error: Cannot use object of type WP_Comment as array’

    Thread Starter eVersatile

    (@eversatile)

    I have kind of figured something out but it’s not working like I want it to.
    Added completely new code to functions.php

    global $post;
    $args = array( 'post_id' => $post->ID );
    $comment = get_comments( $args );
    if ( 3 <= count( $comment ) ){
          $post = array( 'ID' => '1015', 'post_status' => 'private' );
    wp_update_post($post);
    } else {
    //blank
    }

    What that should do, as far as I know, is change the status to private after post 1015 receives 3 comments. What it is doing, is changing post 1015, even without comments.
    Why is it not picking up if it has 3 comments or any at all and changing it anyways? Also, I would actually like for it to work with all posts, I used 1015 as a test.

    Thread Starter eVersatile

    (@eversatile)

    Ok. I get what you are saying and it really does help but it does not solve the problem. I don’t have a code to change the status, that is what I really need help with. I don’t know what to use to change the status.

    Thread Starter eVersatile

    (@eversatile)

    I have tried using that filter different ways and it never worked. There’s nothing in wp_insert_comment that’ll change the status of the post….. could you elaborate a little?

    Thread Starter eVersatile

    (@eversatile)

    I have tried using that codex to accomplish what I am trying to do but have not come up with a solution yet.
    I have also tried using the information at THIS LINK
    Though, I am starting to think I may be able to accomplish this using a existing code I have made on the site.
    The current code is

    global $post,$current_user;
    $args = array( 'post_id' => $post->ID );
    $comment = get_comments( $args );
      get_currentuserinfo();
      if ($post->post_author == $current_user->ID && 3 <= count( $comment ) ){
        echo do_shortcode( '[button]' );
    } elseif ( 3 <= count( $comment ) ) {
    //blank
    } else {
        comment_form();
    }

    Would I be able to hook into something under ‘elseif’ to change the post to private?

    Thread Starter eVersatile

    (@eversatile)

    I have actually created a custom status called ‘archive’ it kind of works like ‘draft’. Though after further testing, I now know this is not going to work for me.
    I would actually like to change it to a ‘private’ post after it receives a comment.

    Thread Starter eVersatile

    (@eversatile)

    After a ton of playing around with the code, I have found the solution.

    global $post,$current_user;
    $args = array( 'post_id' => $post->ID );
    $comment = get_comments( $args );
      get_currentuserinfo();
      if ($post->post_author == $current_user->ID ) {
        echo do_shortcode( '[button]' );
    } elseif ( 3 <= count( $comment ) ) {
    // blank
    } else {
        comment_form();
    }
Viewing 15 replies - 1 through 15 (of 21 total)