• 1) register multiple CPT
    2) set page to archive via option page
    3) look over plugin Query Monitor

    I have 5 CPT with archive page. Plugin create 5 SQL query, which can be handled by 1.

    
     public function initialise() {
            $this->basename = plugin_basename(__FILE__);
            if ( $pages = array_unique( array_filter( array_values( (array)$this->get_config() ) ) ) )
                $cache_pages = get_posts( array( 'post_type' => 'any', 'numberposts' => -1, 'post__in' => $pages ) );
    

    change get_page to get_post

    
        public function get_archive_page( $slug = null ) {
            $page_id = $this->get_archive_page_id( $slug );
            return $page_id ? get_post($page_id) : null;
        }
    
Viewing 1 replies (of 1 total)
  • Thread Starter Hrohh

    (@hrohh)

    better without saving to memory, suppress_filters and we dont need POSTMETA to query

    
    if ( $pages = array_unique( array_filter( array_values( (array)$this->get_config() ) ) ) )
                new WP_Query( array(
                    'post_type'              => 'any',
                    'post_status'            => array( 'publish'),
                    'posts_per_page'         => -1,
                    'suppress_filters'       => true,
                    'post__in'               => $pages,
                    'ignore_sticky_posts'    => true,
                    'no_found_rows'          => true,
                    'update_post_meta_cache' => false,
                    'update_post_term_cache' => false
                ));
    
    • This reply was modified 5 years, 5 months ago by Hrohh.
    • This reply was modified 5 years, 5 months ago by Hrohh.
    • This reply was modified 5 years, 5 months ago by Hrohh.
Viewing 1 replies (of 1 total)

The topic ‘Multiple SQL query, but it is not necessary’ is closed to new replies.