wordpress show posts form category menu active










0















In WordPress I have a right menu with the code:



 <?php wp_list_categories( array(
'orderby' => 'name',
'show_count' => false,
'exclude' => array( 1,2,3,4 )
) ); ?>


and the query to show posts:



 <?php
// the query
$wpb_all_query = new WP_Query(array('post_type'=>'documentos', 'order' => 'ASC', 'post_status'=>'publish'));
?>

<?php if ( $wpb_all_query->have_posts() ) : ?>
<h4 class="titDocCat" ><?php single_cat_title(); ?></h4>
<ul class="doc">

<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>


<li class="gobierno">
<div class="kc_col-sm-9 kc_column kc_col-sm-9 noPad">
<h3 class="titleDoc"><?php the_field('titular_del_documento'); ?></h3>
<p class="smallDoc"><?php the_field('descripcion_del_documento'); ?></p>
</div>

<div class="kc_col-sm-3 kc_column kc_col-sm-3 noPad">
<a class="btnDownload" href="<?php the_field('archivo'); ?>" download><?php _e( 'Descarga PDF', 'modrox' ); ?></a>
</div>

</li>
<div class="sepGob"></div>
<?php endwhile; ?>
<!-- end of the loop -->
</ul>

<?php wp_reset_postdata(); ?>

<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.', 'modrox' ); ?></p>
<?php endif; ?>


But when I click a category from the menu, always shows me all posts, from custom post type. How can I do to show only the category selected from the menu










share|improve this question




























    0















    In WordPress I have a right menu with the code:



     <?php wp_list_categories( array(
    'orderby' => 'name',
    'show_count' => false,
    'exclude' => array( 1,2,3,4 )
    ) ); ?>


    and the query to show posts:



     <?php
    // the query
    $wpb_all_query = new WP_Query(array('post_type'=>'documentos', 'order' => 'ASC', 'post_status'=>'publish'));
    ?>

    <?php if ( $wpb_all_query->have_posts() ) : ?>
    <h4 class="titDocCat" ><?php single_cat_title(); ?></h4>
    <ul class="doc">

    <!-- the loop -->
    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>


    <li class="gobierno">
    <div class="kc_col-sm-9 kc_column kc_col-sm-9 noPad">
    <h3 class="titleDoc"><?php the_field('titular_del_documento'); ?></h3>
    <p class="smallDoc"><?php the_field('descripcion_del_documento'); ?></p>
    </div>

    <div class="kc_col-sm-3 kc_column kc_col-sm-3 noPad">
    <a class="btnDownload" href="<?php the_field('archivo'); ?>" download><?php _e( 'Descarga PDF', 'modrox' ); ?></a>
    </div>

    </li>
    <div class="sepGob"></div>
    <?php endwhile; ?>
    <!-- end of the loop -->
    </ul>

    <?php wp_reset_postdata(); ?>

    <?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.', 'modrox' ); ?></p>
    <?php endif; ?>


    But when I click a category from the menu, always shows me all posts, from custom post type. How can I do to show only the category selected from the menu










    share|improve this question


























      0












      0








      0








      In WordPress I have a right menu with the code:



       <?php wp_list_categories( array(
      'orderby' => 'name',
      'show_count' => false,
      'exclude' => array( 1,2,3,4 )
      ) ); ?>


      and the query to show posts:



       <?php
      // the query
      $wpb_all_query = new WP_Query(array('post_type'=>'documentos', 'order' => 'ASC', 'post_status'=>'publish'));
      ?>

      <?php if ( $wpb_all_query->have_posts() ) : ?>
      <h4 class="titDocCat" ><?php single_cat_title(); ?></h4>
      <ul class="doc">

      <!-- the loop -->
      <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>


      <li class="gobierno">
      <div class="kc_col-sm-9 kc_column kc_col-sm-9 noPad">
      <h3 class="titleDoc"><?php the_field('titular_del_documento'); ?></h3>
      <p class="smallDoc"><?php the_field('descripcion_del_documento'); ?></p>
      </div>

      <div class="kc_col-sm-3 kc_column kc_col-sm-3 noPad">
      <a class="btnDownload" href="<?php the_field('archivo'); ?>" download><?php _e( 'Descarga PDF', 'modrox' ); ?></a>
      </div>

      </li>
      <div class="sepGob"></div>
      <?php endwhile; ?>
      <!-- end of the loop -->
      </ul>

      <?php wp_reset_postdata(); ?>

      <?php else : ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.', 'modrox' ); ?></p>
      <?php endif; ?>


      But when I click a category from the menu, always shows me all posts, from custom post type. How can I do to show only the category selected from the menu










      share|improve this question
















      In WordPress I have a right menu with the code:



       <?php wp_list_categories( array(
      'orderby' => 'name',
      'show_count' => false,
      'exclude' => array( 1,2,3,4 )
      ) ); ?>


      and the query to show posts:



       <?php
      // the query
      $wpb_all_query = new WP_Query(array('post_type'=>'documentos', 'order' => 'ASC', 'post_status'=>'publish'));
      ?>

      <?php if ( $wpb_all_query->have_posts() ) : ?>
      <h4 class="titDocCat" ><?php single_cat_title(); ?></h4>
      <ul class="doc">

      <!-- the loop -->
      <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>


      <li class="gobierno">
      <div class="kc_col-sm-9 kc_column kc_col-sm-9 noPad">
      <h3 class="titleDoc"><?php the_field('titular_del_documento'); ?></h3>
      <p class="smallDoc"><?php the_field('descripcion_del_documento'); ?></p>
      </div>

      <div class="kc_col-sm-3 kc_column kc_col-sm-3 noPad">
      <a class="btnDownload" href="<?php the_field('archivo'); ?>" download><?php _e( 'Descarga PDF', 'modrox' ); ?></a>
      </div>

      </li>
      <div class="sepGob"></div>
      <?php endwhile; ?>
      <!-- end of the loop -->
      </ul>

      <?php wp_reset_postdata(); ?>

      <?php else : ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.', 'modrox' ); ?></p>
      <?php endif; ?>


      But when I click a category from the menu, always shows me all posts, from custom post type. How can I do to show only the category selected from the menu







      wordpress categories






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 11:39









      Gufran Hasan

      3,56741426




      3,56741426










      asked Nov 13 '18 at 11:22









      rinkaslbrinkaslb

      477




      477






















          2 Answers
          2






          active

          oldest

          votes


















          0














          <?php $wpb_all_query = new WP_Query(array('post_type' => 'documentos', 'order' => 'ASC', 'post_status' => 'publish', 'cat_name' => 'category_slug')); ?>


          You should have to add "cat_name" parameter in your query and have to pass category slug into it.






          share|improve this answer






























            0














            You need to modify your query as:



             $pargs = array(
            'post_per_page' => '-1',
            'post_type' => 'documentos',
            'tax_query' => array(
            array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => $term_slugs
            ),
            'post_status'=>'publish'
            );

            $wpb_all_query = new WP_Query($pargs);


            Note: $term_slugs is a category slug name.



            This is the working code:



            <?php
            // find last word from URL ( this will basically give you "rings" )
            $cat = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );

            // the query
            $args = array(
            'post_type' => 'documentos',
            'posts_per_page' => -1,
            'orderby' => 'DATE',
            'order' => 'ASC',
            'tax_query' => array(
            array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => esc_attr( $cat ),
            ),
            ),
            );

            // query results
            $the_query = new WP_Query( $args );

            // display results
            if ( $the_query->have_posts() )
            while ( $the_query->have_posts() )
            $the_query->the_post();
            echo '<h2>' . get_the_title() . '</h2>';

            // reset post
            wp_reset_postdata();

            ?>


            Reference link






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279950%2fwordpress-show-posts-form-category-menu-active%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              <?php $wpb_all_query = new WP_Query(array('post_type' => 'documentos', 'order' => 'ASC', 'post_status' => 'publish', 'cat_name' => 'category_slug')); ?>


              You should have to add "cat_name" parameter in your query and have to pass category slug into it.






              share|improve this answer



























                0














                <?php $wpb_all_query = new WP_Query(array('post_type' => 'documentos', 'order' => 'ASC', 'post_status' => 'publish', 'cat_name' => 'category_slug')); ?>


                You should have to add "cat_name" parameter in your query and have to pass category slug into it.






                share|improve this answer

























                  0












                  0








                  0







                  <?php $wpb_all_query = new WP_Query(array('post_type' => 'documentos', 'order' => 'ASC', 'post_status' => 'publish', 'cat_name' => 'category_slug')); ?>


                  You should have to add "cat_name" parameter in your query and have to pass category slug into it.






                  share|improve this answer













                  <?php $wpb_all_query = new WP_Query(array('post_type' => 'documentos', 'order' => 'ASC', 'post_status' => 'publish', 'cat_name' => 'category_slug')); ?>


                  You should have to add "cat_name" parameter in your query and have to pass category slug into it.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 11:44









                  Mehul JogiMehul Jogi

                  11




                  11























                      0














                      You need to modify your query as:



                       $pargs = array(
                      'post_per_page' => '-1',
                      'post_type' => 'documentos',
                      'tax_query' => array(
                      array(
                      'taxonomy' => 'category',
                      'field' => 'slug',
                      'terms' => $term_slugs
                      ),
                      'post_status'=>'publish'
                      );

                      $wpb_all_query = new WP_Query($pargs);


                      Note: $term_slugs is a category slug name.



                      This is the working code:



                      <?php
                      // find last word from URL ( this will basically give you "rings" )
                      $cat = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );

                      // the query
                      $args = array(
                      'post_type' => 'documentos',
                      'posts_per_page' => -1,
                      'orderby' => 'DATE',
                      'order' => 'ASC',
                      'tax_query' => array(
                      array(
                      'taxonomy' => 'category',
                      'field' => 'slug',
                      'terms' => esc_attr( $cat ),
                      ),
                      ),
                      );

                      // query results
                      $the_query = new WP_Query( $args );

                      // display results
                      if ( $the_query->have_posts() )
                      while ( $the_query->have_posts() )
                      $the_query->the_post();
                      echo '<h2>' . get_the_title() . '</h2>';

                      // reset post
                      wp_reset_postdata();

                      ?>


                      Reference link






                      share|improve this answer





























                        0














                        You need to modify your query as:



                         $pargs = array(
                        'post_per_page' => '-1',
                        'post_type' => 'documentos',
                        'tax_query' => array(
                        array(
                        'taxonomy' => 'category',
                        'field' => 'slug',
                        'terms' => $term_slugs
                        ),
                        'post_status'=>'publish'
                        );

                        $wpb_all_query = new WP_Query($pargs);


                        Note: $term_slugs is a category slug name.



                        This is the working code:



                        <?php
                        // find last word from URL ( this will basically give you "rings" )
                        $cat = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );

                        // the query
                        $args = array(
                        'post_type' => 'documentos',
                        'posts_per_page' => -1,
                        'orderby' => 'DATE',
                        'order' => 'ASC',
                        'tax_query' => array(
                        array(
                        'taxonomy' => 'category',
                        'field' => 'slug',
                        'terms' => esc_attr( $cat ),
                        ),
                        ),
                        );

                        // query results
                        $the_query = new WP_Query( $args );

                        // display results
                        if ( $the_query->have_posts() )
                        while ( $the_query->have_posts() )
                        $the_query->the_post();
                        echo '<h2>' . get_the_title() . '</h2>';

                        // reset post
                        wp_reset_postdata();

                        ?>


                        Reference link






                        share|improve this answer



























                          0












                          0








                          0







                          You need to modify your query as:



                           $pargs = array(
                          'post_per_page' => '-1',
                          'post_type' => 'documentos',
                          'tax_query' => array(
                          array(
                          'taxonomy' => 'category',
                          'field' => 'slug',
                          'terms' => $term_slugs
                          ),
                          'post_status'=>'publish'
                          );

                          $wpb_all_query = new WP_Query($pargs);


                          Note: $term_slugs is a category slug name.



                          This is the working code:



                          <?php
                          // find last word from URL ( this will basically give you "rings" )
                          $cat = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );

                          // the query
                          $args = array(
                          'post_type' => 'documentos',
                          'posts_per_page' => -1,
                          'orderby' => 'DATE',
                          'order' => 'ASC',
                          'tax_query' => array(
                          array(
                          'taxonomy' => 'category',
                          'field' => 'slug',
                          'terms' => esc_attr( $cat ),
                          ),
                          ),
                          );

                          // query results
                          $the_query = new WP_Query( $args );

                          // display results
                          if ( $the_query->have_posts() )
                          while ( $the_query->have_posts() )
                          $the_query->the_post();
                          echo '<h2>' . get_the_title() . '</h2>';

                          // reset post
                          wp_reset_postdata();

                          ?>


                          Reference link






                          share|improve this answer















                          You need to modify your query as:



                           $pargs = array(
                          'post_per_page' => '-1',
                          'post_type' => 'documentos',
                          'tax_query' => array(
                          array(
                          'taxonomy' => 'category',
                          'field' => 'slug',
                          'terms' => $term_slugs
                          ),
                          'post_status'=>'publish'
                          );

                          $wpb_all_query = new WP_Query($pargs);


                          Note: $term_slugs is a category slug name.



                          This is the working code:



                          <?php
                          // find last word from URL ( this will basically give you "rings" )
                          $cat = basename( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );

                          // the query
                          $args = array(
                          'post_type' => 'documentos',
                          'posts_per_page' => -1,
                          'orderby' => 'DATE',
                          'order' => 'ASC',
                          'tax_query' => array(
                          array(
                          'taxonomy' => 'category',
                          'field' => 'slug',
                          'terms' => esc_attr( $cat ),
                          ),
                          ),
                          );

                          // query results
                          $the_query = new WP_Query( $args );

                          // display results
                          if ( $the_query->have_posts() )
                          while ( $the_query->have_posts() )
                          $the_query->the_post();
                          echo '<h2>' . get_the_title() . '</h2>';

                          // reset post
                          wp_reset_postdata();

                          ?>


                          Reference link







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 13 '18 at 11:49

























                          answered Nov 13 '18 at 11:43









                          Gufran HasanGufran Hasan

                          3,56741426




                          3,56741426



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279950%2fwordpress-show-posts-form-category-menu-active%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Use pre created SQLite database for Android project in kotlin

                              Darth Vader #20

                              Ondo