0

I have setup my widget to retrieve data from custom post types. I am using WP Query to show the data, but it still not showing.

I have also setup the file in a gist for easier lookup https://gist.github.com/609fc97c0352820eb762.git

Soccer Clubs Movies Xbox Games Sermons array('soccer-club'), );

                                            //Custom query
                                            $tabbedquery = new WP_Query($args);
                                            ?>

                                            <?php 
                                                if ($tabbedquery->have_posts()) {
                                                    while ($tabbedquery->have_posts()) {
                                                        $tabbedquery->the_post();

                                                        ?>

                                                        <p><?php the_excerpt(); ?></p>

                                                    <?php
                                                    }
                                                }

                                                /** Restore original postdata */
                                                wp_reset_postdata();
                                        }

                                        function f557_posts_widget_init(){
                                            register_sidebar_widget('Recent Soccer Clubs', 'f557query_posts_widget');
                                        }
                                        add_action('widgets_init', 'f557_posts_widget_init');

                                        ?>
                              </div>
                            </div>

                            <a href="#panel2" class="show-for-small-only"><i class="fa fa-calendar"></i> Movies</a>
                            <div id="panel2" class="content">
                                <div class="content-box section-box">
                                    <!--Insert PHP Query Here-->
                              </div>
                            </div>

                            <a href="#panel3" class="show-for-small-only"><i class="fa fa-bed"></i> Xbox Games</a>
                            <div id="panel3" class="content">
                                <div class="content-box section-box">
                                    <!--Insert PHP Query Here-->
                              </div>
                            </div>


                        </dd>
                    </dl>
                </div>
        </article>
  • I have check your code why the function inside the function line number 204 – Mitul Jun 22 '15 at 7:26
  • @Mitul were you able to figure out what is causing the query not to work? – James Gacuca Jun 23 '15 at 13:20
  • yes sure I will figure out – Mitul Jun 24 '15 at 4:31
1

Please find the code its working you need to just add the js and css for your design

it will add three custom post and add widget to the widget area you can drag and drop it in any side bar.

<?php
/**
 * Plugin Name:       Custom Tabbed Plugin
 * Description:       This is testing of the custom tabbed plugin
 * Version:           1.0.2
 * Author:            James Van Waza
 * Author URI:        http://jamesvanwaza.com
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 */

/**
 * Registers a new post type
 * @uses $wp_post_types Inserts new post type object into the list
 *
 * @param string  Post type key, must not exceed 20 characters
 * @param array|string  See optional args description above.
 * @return object|WP_Error the registered post type object, or an error object
 */

add_action('init', 'aip_popup_init');

function add_custom_post_type(){
    $labels = array(
        'name' => __('Soccer Clubs', 'text-domain') ,
        'singular_name' => __('Soccer Club', 'text-domain') ,
        'add_new' => _x('Add New Soccer Club', 'text-domain', 'text-domain') ,
        'add_new_item' => __('Add New Soccer Club', 'text-domain') ,
        'edit_item' => __('Edit Soccer Club', 'text-domain') ,
        'new_item' => __('New Soccer Club', 'text-domain') ,
        'view_item' => __('View Soccer Club', 'text-domain') ,
        'search_items' => __('Search Soccer Clubs', 'text-domain') ,
        'not_found' => __('No Soccer Clubs found', 'text-domain') ,
        'not_found_in_trash' => __('No Soccer Clubs found in Trash', 'text-domain') ,
        'parent_item_colon' => __('Parent Soccer Club:', 'text-domain') ,
        'menu_name' => __('Soccer Clubs', 'text-domain')
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
        'description' => 'description',
        'taxonomies' => array() ,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_admin_bar' => true,
        'menu_position' => null,
        'menu_icon' => null,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array(
            'slug' => 'soccer-club'
        ) ,
        'capability_type' => 'post',
        'supports' => array(
            'title',
            'editor',
            'author',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'trackbacks',
            'comments',
            'revisions',
            'page-attributes',
            'post-formats'
        )
    );
    register_post_type('soccer-club', $args);
    $labels = array(
        'name' => __('Movies', 'text-domain') ,
        'singular_name' => __('Movie', 'text-domain') ,
        'add_new' => _x('Add New Movie', 'text-domain', 'text-domain') ,
        'add_new_item' => __('Add New Movie', 'text-domain') ,
        'edit_item' => __('Edit Movie', 'text-domain') ,
        'new_item' => __('New Movie', 'text-domain') ,
        'view_item' => __('View Movie', 'text-domain') ,
        'search_items' => __('Search Movies', 'text-domain') ,
        'not_found' => __('No Movies found', 'text-domain') ,
        'not_found_in_trash' => __('No Movies found in Trash', 'text-domain') ,
        'parent_item_colon' => __('Parent Movie:', 'text-domain') ,
        'menu_name' => __('Movies', 'text-domain')
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
        'description' => 'description',
        'taxonomies' => array() ,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_admin_bar' => true,
        'menu_position' => null,
        'menu_icon' => null,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array(
            'slug' => 'movies'
        ) ,
        'capability_type' => 'post',
        'supports' => array(
            'title',
            'editor',
            'author',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'trackbacks',
            'comments',
            'revisions',
            'page-attributes',
            'post-formats'
        )
    );
    register_post_type('movies', $args);


    $labels = array(
        'name' => __('Xbox Games', 'text-domain') ,
        'singular_name' => __('Xbox Game', 'text-domain') ,
        'add_new' => _x('Add New Xbox Game', 'text-domain', 'text-domain') ,
        'add_new_item' => __('Add New Xbox Game', 'text-domain') ,
        'edit_item' => __('Edit Xbox Game', 'text-domain') ,
        'new_item' => __('New Xbox Game', 'text-domain') ,
        'view_item' => __('View Xbox Game', 'text-domain') ,
        'search_items' => __('Search Xbox Games', 'text-domain') ,
        'not_found' => __('No Xbox Games found', 'text-domain') ,
        'not_found_in_trash' => __('No Xbox Games found in Trash', 'text-domain') ,
        'parent_item_colon' => __('Parent Xbox Game:', 'text-domain') ,
        'menu_name' => __('Xbox Games', 'text-domain')
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => false,
        'description' => 'description',
        'taxonomies' => array() ,
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_admin_bar' => true,
        'menu_position' => null,
        'menu_icon' => null,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array(
            'slug' => 'xbox-games'
        ) ,
        'capability_type' => 'post',
        'supports' => array(
            'title',
            'editor',
            'author',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'trackbacks',
            'comments',
            'revisions',
            'page-attributes',
            'post-formats'
        )
    );
    register_post_type('xbox-games', $args);
}

// creating a widget
    class f557TabberWidget extends WP_Widget {


        function __construct() {
            parent::__construct(
                'f557TabberWidget', // Base ID
                __( 'Taber Title', 'text_domain' ), // Name
                array( 'description' => __( 'A Foo Widget', 'text_domain' ), ) // Args
            );
        }

        function f557TabberWidget() {
                $widget_ops = array(
                    'classname' => 'f557TabberWidget',
                    'description' => 'Simple jQuery Tabber Widget'
                );
                $this->WP_Widget(
                        'f557TabberWidget',
                        'f557Beginner Tabber Widget',
                        $widget_ops
                );
        }

        function widget($args, $instance) {
                ?>
                    <div class="small-12 columns">
                        <ul class="tabs show-for-medium-up" data-tab>
                                <li>Soccer Clib</li>
                                <li>Movie</li>
                                <li>Xbox Games</li>
                        </ul>

                        <div class="tab1">
                            <?php
                            $args = array(
                                'post_type' => 'soccer-club',
                                'posts_per_page' => 2
                            );
                            $soccer = new WP_Query($args);
                            if( $soccer->have_posts() ) {
                                while ($soccer->have_posts()) : $soccer->the_post(); ?>
                                    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                                <?php
                                endwhile;
                            }
                            ?>
                        </div>

                        <div class="tab2">
                            <?php
                            $args = array(
                                'post_type' => 'movies',
                                'posts_per_page' => 2
                            );
                            $soccer = new WP_Query($args);
                            if( $soccer->have_posts() ) {
                                while ($soccer->have_posts()) : $soccer->the_post(); ?>
                                    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                                <?php
                                endwhile;
                            }
                            ?>
                        </div>

                        <div class="tab3">
                            <?php
                            $args = array(
                                'post_type' => 'xbox-games',
                                'posts_per_page' => 2
                            );
                            $soccer = new WP_Query($args);
                            if( $soccer->have_posts() ) {
                                while ($soccer->have_posts()) : $soccer->the_post(); ?>
                                    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                                <?php
                                endwhile;
                            }
                            ?>
                        </div>
                    </div>

            <?php
        }
        public function form( $instance ) {

        }
        public function update( $new_instance, $old_instance ) {           
        }
    }

    add_action('widgets_init', function(){
        register_widget( 'f557TabberWidget' );
    });

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.