If newest post of category is newest post in general, skip first post of category












1















currently I am working on some customized blog templating and was wondering if there is any way to find out if the newest post of a category is also the newest post of the whole blog, so I can skip the first post of the category.



enter image description here




  • (1) is the newest post of the whole blog, which is in category (B).

  • (2) is the newest post of the category (A)

  • (3) is the newest post of the category (B), also is (1)


Basically I am asking how I would do this:
If (3) = (1), skip (3) and show 2nd newest post in the category (in this case category (B)).





Additional information about my blog specifically, while the information above is more general/universal.



In my blog I also have a category that is excluded from the blog and only shown on a specific page. How would I exclude this category from the whole solution for the initial question? Would it simply be enough to write 'cat' => -123,?










share|improve this question



























    1















    currently I am working on some customized blog templating and was wondering if there is any way to find out if the newest post of a category is also the newest post of the whole blog, so I can skip the first post of the category.



    enter image description here




    • (1) is the newest post of the whole blog, which is in category (B).

    • (2) is the newest post of the category (A)

    • (3) is the newest post of the category (B), also is (1)


    Basically I am asking how I would do this:
    If (3) = (1), skip (3) and show 2nd newest post in the category (in this case category (B)).





    Additional information about my blog specifically, while the information above is more general/universal.



    In my blog I also have a category that is excluded from the blog and only shown on a specific page. How would I exclude this category from the whole solution for the initial question? Would it simply be enough to write 'cat' => -123,?










    share|improve this question

























      1












      1








      1








      currently I am working on some customized blog templating and was wondering if there is any way to find out if the newest post of a category is also the newest post of the whole blog, so I can skip the first post of the category.



      enter image description here




      • (1) is the newest post of the whole blog, which is in category (B).

      • (2) is the newest post of the category (A)

      • (3) is the newest post of the category (B), also is (1)


      Basically I am asking how I would do this:
      If (3) = (1), skip (3) and show 2nd newest post in the category (in this case category (B)).





      Additional information about my blog specifically, while the information above is more general/universal.



      In my blog I also have a category that is excluded from the blog and only shown on a specific page. How would I exclude this category from the whole solution for the initial question? Would it simply be enough to write 'cat' => -123,?










      share|improve this question














      currently I am working on some customized blog templating and was wondering if there is any way to find out if the newest post of a category is also the newest post of the whole blog, so I can skip the first post of the category.



      enter image description here




      • (1) is the newest post of the whole blog, which is in category (B).

      • (2) is the newest post of the category (A)

      • (3) is the newest post of the category (B), also is (1)


      Basically I am asking how I would do this:
      If (3) = (1), skip (3) and show 2nd newest post in the category (in this case category (B)).





      Additional information about my blog specifically, while the information above is more general/universal.



      In my blog I also have a category that is excluded from the blog and only shown on a specific page. How would I exclude this category from the whole solution for the initial question? Would it simply be enough to write 'cat' => -123,?







      categories loop query blog






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 7 '18 at 14:28









      marvinpoomarvinpoo

      252115




      252115






















          2 Answers
          2






          active

          oldest

          votes


















          3














          So the easiest way to do this would be to store the ID of the first post (1) then in each of your category loops you can use the post__not_in property like so:



          // inside the first loop at the top.
          $latest_post_id = get_the_ID();

          // WP_Query for fetching each category
          $category_query = new WP_Query( [
          // other parameters
          'post__not_in' => [ $latest_post_id ],
          ] );


          Now to exclude a category in WP_Query you can use category__not_in which takes an array of category ID's. It's definitely worth checking out the wordpress codex for WP_Query






          share|improve this answer































            1














            Just use ‘post__not_in’ param in your second query.



            $query1 = new WP_Query...
            $used_posts = array();

            while ( $query1->have_posts() ) :
            $query1->the_post();
            $used_posts= get_the_ID();
            ...
            endwhile;

            $query2 = new WP_Query( array(
            'post__not_in' => $used_posts,
            ...
            ) );





            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "110"
              };
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2fwordpress.stackexchange.com%2fquestions%2f321293%2fif-newest-post-of-category-is-newest-post-in-general-skip-first-post-of-categor%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









              3














              So the easiest way to do this would be to store the ID of the first post (1) then in each of your category loops you can use the post__not_in property like so:



              // inside the first loop at the top.
              $latest_post_id = get_the_ID();

              // WP_Query for fetching each category
              $category_query = new WP_Query( [
              // other parameters
              'post__not_in' => [ $latest_post_id ],
              ] );


              Now to exclude a category in WP_Query you can use category__not_in which takes an array of category ID's. It's definitely worth checking out the wordpress codex for WP_Query






              share|improve this answer




























                3














                So the easiest way to do this would be to store the ID of the first post (1) then in each of your category loops you can use the post__not_in property like so:



                // inside the first loop at the top.
                $latest_post_id = get_the_ID();

                // WP_Query for fetching each category
                $category_query = new WP_Query( [
                // other parameters
                'post__not_in' => [ $latest_post_id ],
                ] );


                Now to exclude a category in WP_Query you can use category__not_in which takes an array of category ID's. It's definitely worth checking out the wordpress codex for WP_Query






                share|improve this answer


























                  3












                  3








                  3







                  So the easiest way to do this would be to store the ID of the first post (1) then in each of your category loops you can use the post__not_in property like so:



                  // inside the first loop at the top.
                  $latest_post_id = get_the_ID();

                  // WP_Query for fetching each category
                  $category_query = new WP_Query( [
                  // other parameters
                  'post__not_in' => [ $latest_post_id ],
                  ] );


                  Now to exclude a category in WP_Query you can use category__not_in which takes an array of category ID's. It's definitely worth checking out the wordpress codex for WP_Query






                  share|improve this answer













                  So the easiest way to do this would be to store the ID of the first post (1) then in each of your category loops you can use the post__not_in property like so:



                  // inside the first loop at the top.
                  $latest_post_id = get_the_ID();

                  // WP_Query for fetching each category
                  $category_query = new WP_Query( [
                  // other parameters
                  'post__not_in' => [ $latest_post_id ],
                  ] );


                  Now to exclude a category in WP_Query you can use category__not_in which takes an array of category ID's. It's definitely worth checking out the wordpress codex for WP_Query







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 7 '18 at 14:37









                  jrmdjrmd

                  1315




                  1315

























                      1














                      Just use ‘post__not_in’ param in your second query.



                      $query1 = new WP_Query...
                      $used_posts = array();

                      while ( $query1->have_posts() ) :
                      $query1->the_post();
                      $used_posts= get_the_ID();
                      ...
                      endwhile;

                      $query2 = new WP_Query( array(
                      'post__not_in' => $used_posts,
                      ...
                      ) );





                      share|improve this answer






























                        1














                        Just use ‘post__not_in’ param in your second query.



                        $query1 = new WP_Query...
                        $used_posts = array();

                        while ( $query1->have_posts() ) :
                        $query1->the_post();
                        $used_posts= get_the_ID();
                        ...
                        endwhile;

                        $query2 = new WP_Query( array(
                        'post__not_in' => $used_posts,
                        ...
                        ) );





                        share|improve this answer




























                          1












                          1








                          1







                          Just use ‘post__not_in’ param in your second query.



                          $query1 = new WP_Query...
                          $used_posts = array();

                          while ( $query1->have_posts() ) :
                          $query1->the_post();
                          $used_posts= get_the_ID();
                          ...
                          endwhile;

                          $query2 = new WP_Query( array(
                          'post__not_in' => $used_posts,
                          ...
                          ) );





                          share|improve this answer















                          Just use ‘post__not_in’ param in your second query.



                          $query1 = new WP_Query...
                          $used_posts = array();

                          while ( $query1->have_posts() ) :
                          $query1->the_post();
                          $used_posts= get_the_ID();
                          ...
                          endwhile;

                          $query2 = new WP_Query( array(
                          'post__not_in' => $used_posts,
                          ...
                          ) );






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 7 '18 at 14:43

























                          answered Dec 7 '18 at 14:37









                          Krzysiek DróżdżKrzysiek Dróżdż

                          15.9k63044




                          15.9k63044






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to WordPress Development Stack Exchange!


                              • 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%2fwordpress.stackexchange.com%2fquestions%2f321293%2fif-newest-post-of-category-is-newest-post-in-general-skip-first-post-of-categor%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

                              Willebadessen

                              Ida-Boy-Ed-Garten

                              Residenzschloss Arolsen