0

product/office/

return 404 error.How is that even possible? should it not go down to index if page is not found ?

This is my archive.php file:

<?php
  get_header();
?>
<div id="wrapper">
  <main id="main" class="site-main" role="main">
    <div class="container">
        <?php
        get_header();
        if(have_posts()) : while(have_posts()) : the_post();
          echo '<a class="a-product" href="'.get_permalink().'">'; 
          echo '<div class="col col-s-1 col-m-4">';
          the_post_thumbnail( 'large', array( 'class' => 'product-img' ));
          echo '<h2 class="h-product">';
            the_title();
          echo '</h2>';
          // echo substr(get_the_content(), 0, 100).'...';
          echo '</div>';
          echo '</a>';
        endwhile; endif;
        ?>
    </div>
  </main><!-- #main -->
</div><!-- #primary -->

  <?php get_sidebar(); ?>
<?php get_footer(); ?>
</body>
</html>

And this is my function.php What do I do wrong ?

<?php 

function create_product_taxonomies() {
  $labels = array(
    'name'                       => _x( 'Products', 'taxonomy general name', 'textdomain' ),
    'singular_name'              => _x( 'Product', 'taxonomy singular name', 'textdomain' ),
    'search_items'               => __( 'Search Products', 'textdomain' ),
    'popular_items'              => __( 'Popular Products', 'textdomain' ),
    'all_items'                  => __( 'All Products', 'textdomain' ),
    'parent_item'                => __( 'Parent product', 'textdomain' ),
    'parent_item_colon'          => __( 'Parent product:', 'textdomain' ),
    'edit_item'                  => __( 'Edit Product', 'textdomain' ),
    'update_item'                => __( 'Update Product', 'textdomain' ),
    'add_new_item'               => __( 'Add New Product', 'textdomain' ),
    'new_item_name'              => __( 'New Product Name', 'textdomain' ),
    'separate_items_with_commas' => __( 'Separate Products with commas', 'textdomain' ),
    'add_or_remove_items'        => __( 'Add or remove Products', 'textdomain' ),
    'choose_from_most_used'      => __( 'Choose from the most used Products', 'textdomain' ),
    'not_found'                  => __( 'No Products found.', 'textdomain' ),
    'menu_name'                  => __( 'Products', 'textdomain' ),
  );

  $args = array(
    'hierarchical'          => true,
    'public'            =>  true,
    'labels'                => $labels,
    'show_ui'               => true,
    'show_admin_column'     => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var'             => true,
    'has_archive'           =>  true,
    'rewrite'               => array( 'slug' => 'products', 'with_front' => false ),
  );

  register_taxonomy( 'product', ['product'], $args );
}

add_action( 'init', 'create_product_taxonomies' );

function custom_product_post() {

  $labels = array(
    'name'                => __( 'Products', 'text-domain' ),
    'singular_name'       => __( 'Product', 'text-domain' ),
    'add_new'             => _x( 'Add New Product', 'text-domain', 'text-domain' ),
    'add_new_item'        => __( 'Add New Product', 'text-domain' ),
    'edit_item'           => __( 'Edit Product', 'text-domain' ),
    'new_item'            => __( 'New Product', 'text-domain' ),
    'view_item'           => __( 'View Product', 'text-domain' ),
    'search_items'        => __( 'Search Products', 'text-domain' ),
    'not_found'           => __( 'No Products found', 'text-domain' ),
    'not_found_in_trash'  => __( 'No Products found in Trash', 'text-domain' ),
    'parent_item_colon'   => __( 'Parent Product:', 'text-domain' ),
    'menu_name'           => __( 'Products', 'text-domain' ),
  );

  $args = array(
    'labels'              => $labels,
    'hierarchical'        => false,
    'description'         => 'Wykonane zlecenia',
    'taxonomies'          => ['products'],
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => 'dashicons-portfolio',
    'show_in_nav_menus'   => true,
    'publicly_queryable'  => true,
    'exclude_from_search' => false,
    'has_archive'         => true,
    'query_var'           => true,
    'can_export'          => true,
    'rewrite'             => true,
    'capability_type'     => 'post',
    'supports'            => array(
      'title', 'editor', 'author', 'thumbnail',
      'excerpt','custom-fields', 'trackbacks', 'comments',
      'revisions', 'page-attributes', 'post-formats'
      )
  );

  register_post_type( 'product', $args );
}

add_action('init', 'custom_product_post');
  • You are trying to fetch the url product/office/ but you register the slug products (with an s at the end) in the rewrite array. And don't forget to update your permalink structure as @Narek suggests. Hint: using the same slug for the cpt and the taxonomy won't work, although there are plugins, which should make that work. – JHoffmann Jan 31 '17 at 12:20
1

Try to update the permalink structure In the Settings → Permalinks panel

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.