Home Forums WTI Like Post PRO custom post type taxonomy

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #699
    ジョンジョン
    Participant

    Specify custom post type with widget.

    I would like to specify a taxonomy or term.

    Please tell me the code to write in functions.php.

    #700
    ジョンジョン
    Participant

    l

    There is a contributor before. There is always a need. Waiting for your answer.

    #701
    ジョンジョン
    Participant

    check
    wti-like-post-site.php

    
    	// Getting the most liked posts
    	$query = "SELECT post_id, SUM(value) AS like_count, post_title, post_author FROM <code>{$wpdb->prefix}wti_like_post</code> L, {$wpdb->prefix}posts P ";
    	$query .= "WHERE L.post_id = P.ID AND post_status = 'publish'";
    	
    	// Get the posts for specific post type
    	if(isset($args['post_type']) && !empty($args['post_type'])) {
    		$post_type = trim($args['post_type']);
    		$query .= " AND P.post_type IN ('" . str_replace(",", "','", $post_type) . "')";
    	}
    
    	

    I want to know the code to add a taxonomy input form with this widget.

    #702
    ジョンジョン
    Participant
    
    function override_WtiMostLikedPostsWidget() {
        class WtiMostLikedPosts_Taxonomy extends WtiMostLikedPosts {
            private $taxonomy = 'category';
     
            public function widget( $args, $instance ) {
                if ( !empty( $instance['taxonomy'] ) ) {
                    $this->taxonomy = $instance['taxonomy'];
                }
    
    #703
    ジョンジョン
    Participant
                add_filter( 'widget_categories_dropdown_args', array( $this, 'add_taxonomy_dropdown_args' ), 10 );
                add_filter( 'widget_categories_args', array( $this, 'add_taxonomy_dropdown_args' ), 10 );
                parent::widget( $args, $instance );
            }
     
    #704
    ジョンジョン
    Participant
            public function form( $instance ) {
                parent::form( $instance );
                $taxonomy = 'category';
                if ( !empty( $instance['taxonomy'] ) ) {
                    $taxonomy = $instance['taxonomy'];
                }
                $taxonomies = $this->get_taxonomies();
                ?>
    #705
    ジョンジョン
    Participant
               <p>
                    <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Taxonomy:' ); ?></label><br />
                    <select id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>">
                        <?php foreach ( $taxonomies as $value ) : ?>
                        <option value="<?php echo esc_attr( $value ); ?>"<?php selected( $taxonomy, $value ); ?>><?php echo esc_attr( $value ); ?></option>
                        <?php endforeach; ?>
                    </select>
                </p>
    #706
    ジョンジョン
    Participant
                <?php
            }
     
            public function add_taxonomy_dropdown_args( $cat_args ) {
                $cat_args['taxonomy'] = $this->taxonomy;
                return $cat_args;
            }
     
            private function get_taxonomies() {
                $taxonomies = get_taxonomies( array(
                    'public' => true,
                ) );
                return $taxonomies;
            }
        }
        unregister_widget( 'WtiMostLikedPosts' );
        register_widget( 'WtiMostLikedPosts_Taxonomy' );
    }
    add_action( 'widgets_init', 'override_WtiMostLikedPosts' );
    #707
    ジョンジョン
    Participant


    Add this way to functions.php, but what is wrong?

    #711
    Webtechideas
    Keymaster

    It’s all broken here. Can you please share the details over email with whatever code you have written? Also, pass on the theme or plugin which you are using for the custom post type taxonomy.

    #712
    ジョンジョン
    Participant
    #713
    ジョンジョン
    Participant

    Widget to expand.

    class WtiRecentlyLikedPostsWidget extends WP_Widget

    class WtiRecentlyLikedPostsWidget extends WP_Widget

    I want expend widget to taxonomy term.

    ex…..

    ◎post type → post
    ◎post type → custom post type

    ◎category → category_name
    × category → term

    I want to be able to acquire terms

    ————————————————–
    php7
    wordpress4.9
    Custom Post Type UI
    ————————————————–

    how to

    1 functions.php overwrite
    if can not
    2 wti-like-post-widgets.php edit

    #714
    ジョンジョン
    Participant

    It is a very good plugin so please make it a widget that can be filtered by term.

    #717
    Webtechideas
    Keymaster

    Email is support[at]webtechideas.com I think it will be a better approach to customize the existing widget to include taxonomy instead of creating a new one.

    #720
    ジョンジョン
    Participant

    Please tell me the code to add a term to the widget.

Viewing 15 posts - 1 through 15 (of 16 total)
  • The forum ‘WTI Like Post PRO’ is closed to new topics and replies.