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 :
<?php
$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);
while($the_query->have_posts())
{
$the_query->the_post();
?>
thank
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 :
<?php
$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);
while($the_query->have_posts())
{
$the_query->the_post();
?>
thank
Share Improve this question asked Nov 25, 2020 at 14:27 kasra abbaszadehkasra abbaszadeh 111 bronze badge1 Answer
Reset to default 1You 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.