Checking is user author of number of posts?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
1
down vote

favorite












I have this function...



$user = wp_get_current_user();
if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
/* Is subscriber, is in category Locked, has amount of posts */
echo do_shortcode('[shortcode_name]');

} else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
/* Is subscriber, is in category Locked, has NO amount of posts */
echo '<div id="locked">
You are subscriber without number of posts!
</div>';

} else if ( in_category('Locked') ) {
/* Is NOT subscriber, is in category Locked, has NO amount of posts */
echo '<div id="locked">
Login or register pal!
</div>';

} else {
/* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
echo do_shortcode('[shortcode_name]');
}


I need to apply "has amount of posts" or "check if user is author of numebr of posts" on first part of code...



if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) && ?????


If this way can't work, I would have one more possible solution, it is to auto move user from subscriber to contributor once subscriber posted number of posts, but this first solution would be better.










share|improve this question






























    up vote
    1
    down vote

    favorite












    I have this function...



    $user = wp_get_current_user();
    if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
    /* Is subscriber, is in category Locked, has amount of posts */
    echo do_shortcode('[shortcode_name]');

    } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
    /* Is subscriber, is in category Locked, has NO amount of posts */
    echo '<div id="locked">
    You are subscriber without number of posts!
    </div>';

    } else if ( in_category('Locked') ) {
    /* Is NOT subscriber, is in category Locked, has NO amount of posts */
    echo '<div id="locked">
    Login or register pal!
    </div>';

    } else {
    /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
    echo do_shortcode('[shortcode_name]');
    }


    I need to apply "has amount of posts" or "check if user is author of numebr of posts" on first part of code...



    if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) && ?????


    If this way can't work, I would have one more possible solution, it is to auto move user from subscriber to contributor once subscriber posted number of posts, but this first solution would be better.










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have this function...



      $user = wp_get_current_user();
      if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
      /* Is subscriber, is in category Locked, has amount of posts */
      echo do_shortcode('[shortcode_name]');

      } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
      /* Is subscriber, is in category Locked, has NO amount of posts */
      echo '<div id="locked">
      You are subscriber without number of posts!
      </div>';

      } else if ( in_category('Locked') ) {
      /* Is NOT subscriber, is in category Locked, has NO amount of posts */
      echo '<div id="locked">
      Login or register pal!
      </div>';

      } else {
      /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
      echo do_shortcode('[shortcode_name]');
      }


      I need to apply "has amount of posts" or "check if user is author of numebr of posts" on first part of code...



      if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) && ?????


      If this way can't work, I would have one more possible solution, it is to auto move user from subscriber to contributor once subscriber posted number of posts, but this first solution would be better.










      share|improve this question















      I have this function...



      $user = wp_get_current_user();
      if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
      /* Is subscriber, is in category Locked, has amount of posts */
      echo do_shortcode('[shortcode_name]');

      } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
      /* Is subscriber, is in category Locked, has NO amount of posts */
      echo '<div id="locked">
      You are subscriber without number of posts!
      </div>';

      } else if ( in_category('Locked') ) {
      /* Is NOT subscriber, is in category Locked, has NO amount of posts */
      echo '<div id="locked">
      Login or register pal!
      </div>';

      } else {
      /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
      echo do_shortcode('[shortcode_name]');
      }


      I need to apply "has amount of posts" or "check if user is author of numebr of posts" on first part of code...



      if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) && ?????


      If this way can't work, I would have one more possible solution, it is to auto move user from subscriber to contributor once subscriber posted number of posts, but this first solution would be better.







      posts functions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 at 22:22









      Krzysiek Dróżdż

      12.8k52637




      12.8k52637










      asked Nov 28 at 22:14









      MLL

      355




      355






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          I guess count_user_posts is what you're looking for ;)



          This is how you use it:



          $user_post_count = count_user_posts( $userid , $post_type );


          And it returns the number of published posts the user has written in this post type.



          PS. And if you want some more advanced count, get_posts_by_author_sql can come quite handy.






          share|improve this answer





















          • Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
            – MLL
            Nov 28 at 22:47










          • Solved. Thank you!
            – MLL
            Nov 28 at 22:53


















          up vote
          1
          down vote













          Guy above answered correctly, but for anyone needing this further, I will add full code as response too...



          $user = wp_get_current_user();
          $user_ID = get_current_user_id();
          $user_post_count = count_user_posts( $user_ID );
          $my_post_meta = get_post_meta($post->ID, 'shortcode_name', true);


          if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) && $user_post_count == 5 ) {
          /* Is subscriber, is in category Locked, has amount of posts */
          echo do_shortcode('[shortcode_name]');

          } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
          /* Is subscriber, is in category Locked, has NO amount of posts */
          echo '<div id="locked">
          You are subscriber without number of posts!
          </div>';
          } else if (( in_category('Locked') ) && in_array( 'administrator', (array) $user->roles ) ) {
          /* Is subscriber, is in category Locked, has power */
          echo do_shortcode('[shortcode_name]');

          } else if ( in_category('Locked') ) {
          /* Is NOT subscriber, is in category Locked, has NO amount of posts */
          echo '<div id="locked">
          Login or register pal!
          </div>';

          } else if ( ! empty ( $my_post_meta ) ) {
          /* Post meta exist */
          echo do_shortcode('[shortcode_name]');


          } else {

          /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
          /* Post meta NOT exist */
          echo do_shortcode('[shortcode_name_1]');
          }





          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',
            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%2f320505%2fchecking-is-user-author-of-number-of-posts%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








            up vote
            2
            down vote



            accepted










            I guess count_user_posts is what you're looking for ;)



            This is how you use it:



            $user_post_count = count_user_posts( $userid , $post_type );


            And it returns the number of published posts the user has written in this post type.



            PS. And if you want some more advanced count, get_posts_by_author_sql can come quite handy.






            share|improve this answer





















            • Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
              – MLL
              Nov 28 at 22:47










            • Solved. Thank you!
              – MLL
              Nov 28 at 22:53















            up vote
            2
            down vote



            accepted










            I guess count_user_posts is what you're looking for ;)



            This is how you use it:



            $user_post_count = count_user_posts( $userid , $post_type );


            And it returns the number of published posts the user has written in this post type.



            PS. And if you want some more advanced count, get_posts_by_author_sql can come quite handy.






            share|improve this answer





















            • Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
              – MLL
              Nov 28 at 22:47










            • Solved. Thank you!
              – MLL
              Nov 28 at 22:53













            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            I guess count_user_posts is what you're looking for ;)



            This is how you use it:



            $user_post_count = count_user_posts( $userid , $post_type );


            And it returns the number of published posts the user has written in this post type.



            PS. And if you want some more advanced count, get_posts_by_author_sql can come quite handy.






            share|improve this answer












            I guess count_user_posts is what you're looking for ;)



            This is how you use it:



            $user_post_count = count_user_posts( $userid , $post_type );


            And it returns the number of published posts the user has written in this post type.



            PS. And if you want some more advanced count, get_posts_by_author_sql can come quite handy.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 28 at 22:23









            Krzysiek Dróżdż

            12.8k52637




            12.8k52637












            • Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
              – MLL
              Nov 28 at 22:47










            • Solved. Thank you!
              – MLL
              Nov 28 at 22:53


















            • Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
              – MLL
              Nov 28 at 22:47










            • Solved. Thank you!
              – MLL
              Nov 28 at 22:53
















            Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
            – MLL
            Nov 28 at 22:47




            Thank you. Where do I put number of posts I want for the user to be able to see the content? For example I want user to add 5 posts before posts from category Locked become visible to him.
            – MLL
            Nov 28 at 22:47












            Solved. Thank you!
            – MLL
            Nov 28 at 22:53




            Solved. Thank you!
            – MLL
            Nov 28 at 22:53












            up vote
            1
            down vote













            Guy above answered correctly, but for anyone needing this further, I will add full code as response too...



            $user = wp_get_current_user();
            $user_ID = get_current_user_id();
            $user_post_count = count_user_posts( $user_ID );
            $my_post_meta = get_post_meta($post->ID, 'shortcode_name', true);


            if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) && $user_post_count == 5 ) {
            /* Is subscriber, is in category Locked, has amount of posts */
            echo do_shortcode('[shortcode_name]');

            } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
            /* Is subscriber, is in category Locked, has NO amount of posts */
            echo '<div id="locked">
            You are subscriber without number of posts!
            </div>';
            } else if (( in_category('Locked') ) && in_array( 'administrator', (array) $user->roles ) ) {
            /* Is subscriber, is in category Locked, has power */
            echo do_shortcode('[shortcode_name]');

            } else if ( in_category('Locked') ) {
            /* Is NOT subscriber, is in category Locked, has NO amount of posts */
            echo '<div id="locked">
            Login or register pal!
            </div>';

            } else if ( ! empty ( $my_post_meta ) ) {
            /* Post meta exist */
            echo do_shortcode('[shortcode_name]');


            } else {

            /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
            /* Post meta NOT exist */
            echo do_shortcode('[shortcode_name_1]');
            }





            share|improve this answer



























              up vote
              1
              down vote













              Guy above answered correctly, but for anyone needing this further, I will add full code as response too...



              $user = wp_get_current_user();
              $user_ID = get_current_user_id();
              $user_post_count = count_user_posts( $user_ID );
              $my_post_meta = get_post_meta($post->ID, 'shortcode_name', true);


              if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) && $user_post_count == 5 ) {
              /* Is subscriber, is in category Locked, has amount of posts */
              echo do_shortcode('[shortcode_name]');

              } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
              /* Is subscriber, is in category Locked, has NO amount of posts */
              echo '<div id="locked">
              You are subscriber without number of posts!
              </div>';
              } else if (( in_category('Locked') ) && in_array( 'administrator', (array) $user->roles ) ) {
              /* Is subscriber, is in category Locked, has power */
              echo do_shortcode('[shortcode_name]');

              } else if ( in_category('Locked') ) {
              /* Is NOT subscriber, is in category Locked, has NO amount of posts */
              echo '<div id="locked">
              Login or register pal!
              </div>';

              } else if ( ! empty ( $my_post_meta ) ) {
              /* Post meta exist */
              echo do_shortcode('[shortcode_name]');


              } else {

              /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
              /* Post meta NOT exist */
              echo do_shortcode('[shortcode_name_1]');
              }





              share|improve this answer

























                up vote
                1
                down vote










                up vote
                1
                down vote









                Guy above answered correctly, but for anyone needing this further, I will add full code as response too...



                $user = wp_get_current_user();
                $user_ID = get_current_user_id();
                $user_post_count = count_user_posts( $user_ID );
                $my_post_meta = get_post_meta($post->ID, 'shortcode_name', true);


                if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) && $user_post_count == 5 ) {
                /* Is subscriber, is in category Locked, has amount of posts */
                echo do_shortcode('[shortcode_name]');

                } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
                /* Is subscriber, is in category Locked, has NO amount of posts */
                echo '<div id="locked">
                You are subscriber without number of posts!
                </div>';
                } else if (( in_category('Locked') ) && in_array( 'administrator', (array) $user->roles ) ) {
                /* Is subscriber, is in category Locked, has power */
                echo do_shortcode('[shortcode_name]');

                } else if ( in_category('Locked') ) {
                /* Is NOT subscriber, is in category Locked, has NO amount of posts */
                echo '<div id="locked">
                Login or register pal!
                </div>';

                } else if ( ! empty ( $my_post_meta ) ) {
                /* Post meta exist */
                echo do_shortcode('[shortcode_name]');


                } else {

                /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
                /* Post meta NOT exist */
                echo do_shortcode('[shortcode_name_1]');
                }





                share|improve this answer














                Guy above answered correctly, but for anyone needing this further, I will add full code as response too...



                $user = wp_get_current_user();
                $user_ID = get_current_user_id();
                $user_post_count = count_user_posts( $user_ID );
                $my_post_meta = get_post_meta($post->ID, 'shortcode_name', true);


                if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) && $user_post_count == 5 ) {
                /* Is subscriber, is in category Locked, has amount of posts */
                echo do_shortcode('[shortcode_name]');

                } else if (( in_category('Locked') ) && in_array( 'subscriber', (array) $user->roles ) ) {
                /* Is subscriber, is in category Locked, has NO amount of posts */
                echo '<div id="locked">
                You are subscriber without number of posts!
                </div>';
                } else if (( in_category('Locked') ) && in_array( 'administrator', (array) $user->roles ) ) {
                /* Is subscriber, is in category Locked, has power */
                echo do_shortcode('[shortcode_name]');

                } else if ( in_category('Locked') ) {
                /* Is NOT subscriber, is in category Locked, has NO amount of posts */
                echo '<div id="locked">
                Login or register pal!
                </div>';

                } else if ( ! empty ( $my_post_meta ) ) {
                /* Post meta exist */
                echo do_shortcode('[shortcode_name]');


                } else {

                /* Is NOT subscriber, is NOT in category Locked, has NO amount of posts */
                /* Post meta NOT exist */
                echo do_shortcode('[shortcode_name_1]');
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 29 at 16:14

























                answered Nov 28 at 22:53









                MLL

                355




                355






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f320505%2fchecking-is-user-author-of-number-of-posts%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

                    Plaza Victoria

                    Puebla de Zaragoza

                    Musa