I had a problem, I converted an html template to wordpress, now I want a section Category Enable to display content using categories Does anyone know the solution and code? iam use a code and not work for category :

            $a = array(
                'posts_per_page'   =>200,
                'offset'           => 0,
                'cat'               => '',
                'category_name'    => '',
                'orderby'          => 'post_date',
                'order'            => 'DESC',
                'include'          => '',
                'exclude'          => '',
                'meta_key'         => '',
                'meta_value'       => '',
                'post_type'        => 'mahsulat',
                'post_mime_type'   => '',
                'post_parent'      => '',
                'post_status'      => 'publish',
                'suppress_filters' => true );

            $the_query=new WP_Query($a);




You should look at the WordPress Template Hierarchy. If you want to show an archive of your posts you create a template called archive-mahsulat.php where mahsulat is your post type. Then you can add a normal WordPress Loop to the file so it can output posts of that type.

If you're looking to create a category page for your post type you first need to register a taxonomy. Then you can create a archive page called taxonomy-{$taxonomy}.php where {$taxonomy} would be replaced with your specific taxonomy slug.

You don't need to create a custom secondary query for these things, if the PHP template pages exist and are named properly then WordPress will connect the dots and query the data for you.

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.