• I have a custom post registered inside wordpress. There are in total 28 items inside, 20 items per page (default).

    When I navigate to page 2, I still see arond 5-6 items that were on the first page, but in the same time I have some missing items, which I can see only if I choose to see at least 28 items on a single page.

    How can I fix this?

    I have the latest wordpress.

    Here is a screenshot:
    https://imgur.com/a/Cgn4Uxn

    • This topic was modified 7 years, 5 months ago by speedwheel.
    • This topic was modified 7 years, 5 months ago by speedwheel.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @speedwheel,
    can you please paste the code you’re using to display your CPTs?

    Thread Starter speedwheel

    (@speedwheel)

    I think I found the issue, I used WP All Import to import these 28 posts, and in the database they all have the same date (including seconds), so wordpress can’t order them by date using pagination (since they all have the same date). When I order them by title it works fine.

    • This reply was modified 7 years, 5 months ago by speedwheel.
    Thread Starter speedwheel

    (@speedwheel)

    @lucagrandicelli here is the code:

    Class CP_Testimonial {
    	/**
    	 * Initialize all the things
    	 */
    
        public static $post_name = 'testimonial';
        public static $tag_taxonomy = 'testimonial_tag';
    
    	function __construct() {
    		// Actions
            add_action( 'init', array( $this, 'register_cpt' ) );
            add_action( 'after_setup_theme', array( $this, 'register_ct_tags' ), 1 );
    	}
    	/**
    	 * Register the custom post type
    	 */
    	public function register_cpt() {
    		$labels = array(
                'all_items'          => __( 'All Testimonials', 'ediloc' ),
    			'name'               => __( 'Testimonials', 'ediloc' ),
    			'singular_name'      => __( 'Testimonial', 'ediloc' ),
    			'add_new'            => __( 'Add New', 'ediloc' ),
    			'add_new_item'       => __( 'Add New Testimonial', 'ediloc' ),
                'edit_item'          => __( 'Edit Testimonial', 'ediloc' ),
                'update_item'        => __( 'Update Testimonial', 'ediloc' ),
    			'new_item'           => __( 'New Testimonial', 'ediloc' ),
    			'view_item'          => __( 'View Testimonial', 'ediloc' ),
    			'search_items'       => __( 'Search Testimonials', 'ediloc' ),
    			'not_found'          => __( 'No Testimonials found', 'ediloc' ),
    			'not_found_in_trash' => __( 'No Testimonials found in Trash', 'ediloc' ),
    			'parent_item_colon'  => __( 'Parent Testimonial:', 'ediloc' ),
    			'menu_name'          => __( 'Testimonials', 'ediloc' ),
    		);
    		$args = array(
                'labels'              => $labels,
                'description'         => __( 'Testimonials for the website.', 'ediloc' ),
    			'hierarchical'        => false,
    			'supports'            => array( 'title', 'editor', 'thumbnail', 'revisions' ),
    			'public'              => false,
    			'show_ui'             => true,
    			'show_in_rest'        => true,
    			'publicly_queryable'  => false,
    			'exclude_from_search' => true,
                'has_archive'         => false,
                'show_in_menu'        => true,
    		    'show_in_nav_menus'   => true,
    			'query_var'           => true,
                'can_export'          => true,
                'show_in_admin_bar'   => true,
                //'rewrite'             => array( 'slug' => 'testimonial', 'with_front' => false ),
                'menu_position'       => 20,
    			'menu_icon'           => 'dashicons-format-quote',
    			//'template'            => array( array( 'core/quote', array( 'className' => 'is-style-large' ) ) ),
    			//'template_lock'      => 'all',
    		);
    		register_post_type( self::$post_name , $args );
        }
        
        //category type taxonomy tags
        public function register_ct_tags() {
            $labels = array(
                'name' => __( 'Tags', 'ediloc' ),
                'singular_name' => __( 'Tag', 'ediloc' ),
                'search_items' =>  __( 'Search Tag', 'ediloc' ),
                'all_items' => __( 'All Tags', 'ediloc' ),
                'parent_item' => __( 'Parent Tag', 'ediloc' ),
                'parent_item_colon' => __( 'Parent Tag:', 'ediloc' ),
                'edit_item' => __( 'Edit Tag', 'ediloc' ), 
                'update_item' => __( 'Update Tag', 'ediloc' ),
                'add_new_item' => __( 'Add New Tag', 'ediloc' ),
                'new_item_name' => __( 'New Tag Name', 'ediloc' ),
                'menu_name' => __( 'Tags', 'ediloc' ),
            ); 	
    
            register_taxonomy(self::$tag_taxonomy, array(self::$post_name), array(
                'public' => true,   
                'hierarchical' => false,
                'labels' => $labels,
                'show_ui' => true,
                'show_admin_column' => true,
                'show_in_nav_menus' => false,
                'query_var' => true,
                'show_in_rest' => true,
                'rewrite' => array( 'slug' => self::$tag_taxonomy ),
            ));
        }
    
        public static function get_random($limit, $term_ids) {
            $args = array(
                'post_type' => self::$post_name,
                'tax_query' => array( 
                    array( 
                        'taxonomy' => self::$tag_taxonomy,
                        'field' => 'id', 
                        'terms' => $term_ids
                    ) 
                ),
                'orderby'   => 'rand',
                'posts_per_page' => $limit,
             );
            $testimonials = new WP_Query( $args );
            return $testimonials;
        }
    
        public static function get_tags() {
            $tags = [];
            $terms = get_terms( [
                'taxonomy' => self::$tag_taxonomy,
                'hide_empty' => true,
            ]);
            if (!empty($terms)) {
                foreach($terms as $term) {
                    $tags[$term->term_id] = $term->name;
                }
            }
            return $tags;
        }
    }
    new CP_Testimonial();
    • This reply was modified 7 years, 5 months ago by speedwheel.
    • This reply was modified 7 years, 5 months ago by speedwheel.
    • This reply was modified 7 years, 5 months ago by speedwheel.

    Yeah, that’s it for sure.

    Thread Starter speedwheel

    (@speedwheel)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Admin panel custom post pagination showing same results’ is closed to new replies.