• 16-02-2020, 23:33:05
    #1
    Üyeliği durduruldu
    wordpress e php ile yorum nasıl ekleyebilirim acaba?
  • 16-02-2020, 23:45:36
    #2
    Örnek kodları ileteyim hocam.
    function wp_insert_comment( $commentdata ) {
        global $wpdb;
        $data = wp_unslash( $commentdata );
     
        $comment_author       = ! isset( $data['comment_author'] ) ? '' : $data['comment_author'];
        $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
        $comment_author_url   = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
        $comment_author_IP    = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
     
        $comment_date     = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
        $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
     
        $comment_post_ID  = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
        $comment_content  = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
        $comment_karma    = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
        $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
        $comment_agent    = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
        $comment_type     = ! isset( $data['comment_type'] ) ? '' : $data['comment_type'];
        $comment_parent   = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
     
        $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
     
        $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
        if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
            return false;
        }
     
        $id = (int) $wpdb->insert_id;
     
        if ( $comment_approved == 1 ) {
            wp_update_comment_count( $comment_post_ID );
     
            foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
                wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' );
            }
        }
     
        clean_comment_cache( $id );
     
        $comment = get_comment( $id );
     
        // If metadata is provided, store it.
        if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) {
            foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) {
                add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true );
            }
        }
     
        /**
         * Fires immediately after a comment is inserted into the database.
         *
         * @since 2.8.0
         *
         * @param int        $id      The comment ID.
         * @param WP_Comment $comment Comment object.
         */
        do_action( 'wp_insert_comment', $id, $comment );
     
        return $id;
    }
  • 16-02-2020, 23:52:02
    #3
    Üyeliği durduruldu
    ouzkilic adlı üyeden alıntı: mesajı görüntüle
    Örnek kodları ileteyim hocam.
    function wp_insert_comment( $commentdata ) {
        global $wpdb;
        $data = wp_unslash( $commentdata );
     
        $comment_author       = ! isset( $data['comment_author'] ) ? '' : $data['comment_author'];
        $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
        $comment_author_url   = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
        $comment_author_IP    = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
     
        $comment_date     = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
        $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
     
        $comment_post_ID  = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
        $comment_content  = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
        $comment_karma    = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
        $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
        $comment_agent    = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
        $comment_type     = ! isset( $data['comment_type'] ) ? '' : $data['comment_type'];
        $comment_parent   = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
     
        $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
     
        $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
        if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
            return false;
        }
     
        $id = (int) $wpdb->insert_id;
     
        if ( $comment_approved == 1 ) {
            wp_update_comment_count( $comment_post_ID );
     
            foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
                wp_cache_delete( "lastcommentmodified:$timezone", 'timeinfo' );
            }
        }
     
        clean_comment_cache( $id );
     
        $comment = get_comment( $id );
     
        // If metadata is provided, store it.
        if ( isset( $commentdata['comment_meta'] ) && is_array( $commentdata['comment_meta'] ) ) {
            foreach ( $commentdata['comment_meta'] as $meta_key => $meta_value ) {
                add_comment_meta( $comment->comment_ID, $meta_key, $meta_value, true );
            }
        }
     
        /**
         * Fires immediately after a comment is inserted into the database.
         *
         * @since 2.8.0
         *
         * @param int        $id      The comment ID.
         * @param WP_Comment $comment Comment object.
         */
        do_action( 'wp_insert_comment', $id, $comment );
     
        return $id;
    }
    kod çok uzunmuş hocam, bu kısa kodu yokmu - $post_id = wp_insert_post( array(
    'post_title' => $titlem, gibi
  • 17-02-2020, 00:01:14
    #4
    judgedred adlı üyeden alıntı: mesajı görüntüle
    kod çok uzunmuş hocam, bu kısa kodu yokmu - $post_id = wp_insert_post( array(
    'post_title' => $titlem, gibi
    insert post için şunu kullanabilirsiniz..

    /**
     * Writes new posts into wordpress programatically
     *
     * @package WordPress
     */
    
    /** Make sure that the WordPress bootstrap has run before continuing. */
    require(dirname(__FILE__) . '/wp-load.php');
    
    global $user_ID;
    $new_post = array(
    'post_title' => 'My New Post',
    'post_content' => 'Lorem ipsum dolor sit amet...',
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => $user_ID,
    'post_type' => 'post',
    'post_category' => array(0)
    );
    $post_id = wp_insert_post($new_post);
  • 17-02-2020, 00:07:41
    #5
    Üyeliği durduruldu
    ouzkilic adlı üyeden alıntı: mesajı görüntüle
    insert post için şunu kullanabilirsiniz..

    /**
     * Writes new posts into wordpress programatically
     *
     * @package WordPress
     */
    
    /** Make sure that the WordPress bootstrap has run before continuing. */
    require(dirname(__FILE__) . '/wp-load.php');
    
    global $user_ID;
    $new_post = array(
    'post_title' => 'My New Post',
    'post_content' => 'Lorem ipsum dolor sit amet...',
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => $user_ID,
    'post_type' => 'post',
    'post_category' => array(0)
    );
    $post_id = wp_insert_post($new_post);
    çok teşekkür ederim, kod iyi çalışıyo
  • 17-02-2020, 00:08:41
    #6
    judgedred adlı üyeden alıntı: mesajı görüntüle
    çok teşekkür ederim, kod iyi çalışıyo
    Rica ederim hocam. Php alanında her sorun için iletişime geçebilirsiniz.