0

i have custom post type 'catalog' and custom taxonomy 'catalog_category' http://bosfor-alum.ru/catalog/category/okonnye-sistemy/ plugin PageNavi show me 404 error ;( help me, please i use wp_query thx functions.php

// Register Custom Post Type
function catalog() {
$labels = array(
    'name'                => _x( 'Товар', 'Post Type General Name', 'catalog' ),
    'singular_name'       => _x( 'Товар', 'Post Type Singular Name', 'catalog' ),
    'menu_name'           => __( 'Каталог', 'catalog' ),
    'parent_item_colon'   => __( 'Вложенный:', 'catalog' ),
    'all_items'           => __( 'Все', 'catalog' ),
    'view_item'           => __( 'Посмотреть', 'catalog' ),
    'add_new_item'        => __( 'Добавить', 'catalog' ),
    'add_new'             => __( 'Добавить', 'catalog' ),
    'edit_item'           => __( 'Изменить', 'catalog' ),
    'update_item'         => __( 'Обновить', 'catalog' ),
    'search_items'        => __( 'Найти', 'catalog' ),
    'not_found'           => __( 'Не найдено', 'catalog' ),
    'not_found_in_trash'  => __( 'Не найдено', 'catalog' ),
);
$args = array(
    'label'               => __( 'catalog', 'catalog' ),
    'description'         => __( 'Описание', 'catalog' ),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'thumbnail', 'custom-fields', ),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => true,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
);
register_post_type( 'catalog', $args );

}

// Hook into the 'init' action
add_action( 'init', 'catalog', 0 ); 
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
    'name'              => _x( 'Категории', 'taxonomy general name' ),
    'singular_name'     => _x( 'Категория', 'taxonomy singular name' ),
    'search_items'      => __( 'Найти' ),
    'all_items'         => __( 'Все' ),
    'parent_item'       => __( 'Вложенность' ),
    'parent_item_colon' => __( 'Вложенность:' ),
    'edit_item'         => __( 'Изменить' ),
    'update_item'       => __( 'Сохранить' ),
    'add_new_item'      => __( 'Добавить' ),
    'new_item_name'     => __( 'Создать' ),
    'menu_name'         => __( 'Категории' ),
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite' => array( 'slug' => 'catalog/category', 'with_front' => false,    'hierarchical' => true)
);

register_taxonomy( 'catalog_category', array( 'catalog' ), $args );
add_action('admin_init', 'flush_rewrite_rules');
user3896538
  • 43
  • 1
  • 4
  • Can we see the loop you are using? – Mauro Jul 31 '14 at 17:26
  • $query = new WP_Query( array( 'post_type' => 'catalog', 'meta_key' => 'builder', 'meta_value' => $builder, 'posts_per_page' => $count_n) ); while ( $query->have_posts() ) { $query->the_post(); //content here if(function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $query ) ); } wp_reset_postdata(); ?> – user3896538 Aug 02 '14 at 17:06
  • Hope this can help you... http://stackoverflow.com/a/31240231/5084291 It works to me! – unMarcos Jul 06 '15 at 08:24
  • I'm not sure if it han help you, but in my case the error was to have a custom post type and a page with the same name. – Oscar Pérez Jan 30 '17 at 14:09

2 Answers2

0
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

And to the query add this:

$query = new WP_Query( array( 'paged' => $paged, 'post_type' => 'catalog', 'meta_key' => 'builder', 'meta_value' => $builder, 'posts_per_page' => $count_n) )
Mauro
  • 1,472
  • 12
  • 22
0

Since, 'paged' parameter is not specified, to get next set of posts. You can use following code,

if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }

$query = new WP_Query( array( 'posts_per_page' => $count_n, 'paged' => $paged, 'post_type' => 'catalog', 'meta_key' => 'builder', 'meta_value' => $builder) );
Domain
  • 11,562
  • 3
  • 23
  • 44