How do I get id of a category using the return of the category name of the Wordpress function single_cat_title ();

0

Friends I have a menu with the following links from the Products and News categories I want when clicking on any of the links and my category.php < strong> return only posts from the category you clicked on.

I have in my page single_cat_title (); that returns the category name, I would like to know how I can get the ID of this category to use in the $ args array

$ args = array ('post_type' => 'post', 'category' = > CATEGORY_CODE , 'showposts' => 3);

<div class="container">
    <?php
        $args = array('post_type'=>'post', 'category'=>single_cat_title(), 'showposts'=>3);
        $my_posts = get_posts( $args );
        if($my_posts) : foreach($my_posts as $post) : setup_postdata( $post );
     ?>

        <div class="row">
            <div class="col-md-3 col-lg-3">
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(false, array('class'=>'img-responsive img-post-blog')); ?></a>
            </div>
            <div class="col-md-9 col-lg-9">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            </div>
        </div>

     <?php
        endforeach;
        endif;
    ?>
</div>
    
asked by anonymous 01.05.2017 / 06:40

1 answer

1

I solved the problem.

$page_object = get_queried_object();
$categoriaID = get_cat_ID($page_object->cat_name);
$args = array('post_type' => 'post', 'category' => $categoriaID, 'showposts' => 3);

I returned with a reply as this might help.

    
01.05.2017 / 07:13