Title: php code
Last modified: October 5, 2016

---

# php code

 *  Resolved [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/)
 * Hi Andrea,
 * You helped me with showing the total amount of posts in the dropdown box of your
   plugin. It works very nice. Now I’m trying to put the code <?php echo count($
   pbytax_posts); ?> on one of my pages.
 * I’m using the plugin ‘easy code placement’ to make a shortcode of the php code.
   When I do this, it shows a zero. So it looks like the plugin ‘easy code placement’
   does what it promises but it doesn’t show the right amount of posts.
 * I think I need another php code. Can you help me?
 * Willem

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/php-code-32/page/2/?output_format=md) 
[→](https://wordpress.org/support/topic/php-code-32/page/2/?output_format=md)

 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256313)
 * Hello Willem!
 * that string of code works only inside my widget. You won’t have the variable 
   $pbytax_posts if you are outside my widget..
 * Where exactly do you want to display the post counter?
 * this is not related to my plugin, but I will give you an hand if I can. 🙂
 *  Thread Starter [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256441)
 * Hi Andrea,
 * I’m glad that you want to help me. I want to display the post counter on: [http://www.razenberg.nl/categorieen/](http://www.razenberg.nl/categorieen/)
 * I hope you can help me.
 * Willem
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256565)
 * ok I see.
 * that is a single page where you are displaying a list of categories.
    where do
   you want to display the counter exactly?
 * next to each of the categories in the list?
    and if it’s there that you want 
   it, how did you built that list? is it made with a plugin?
 *  Thread Starter [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256624)
 * Hi Andrea,
 * I want to display the counter in the text between ‘alle’ and ‘columns’ in the
   sentence: ‘Je vindt in de rechterkolom ook een dropdown box met de titels van
   alle ….. columns.’
 * I don’t want to display it in the list with categories which is made with the
   plugin ‘table of contents plus’.
 * Willem
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256635)
 * ok I see now.
 * the only thing I’m not sure about is what count do you want to display (sorry
   but I don’t know german..).
 * do you want to display the counter of the total posts in your entire website?
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256645)
 * anyways, wordpress has this simple function to get the total posts
 *     ```
       $count_posts = wp_count_posts();
       $published_posts = $count_posts->publish;
       echo $published_posts;
       ```
   
    -  This reply was modified 9 years, 6 months ago by [piccart](https://wordpress.org/support/users/piccart/).
    -  This reply was modified 9 years, 6 months ago by [piccart](https://wordpress.org/support/users/piccart/).
 *  Thread Starter [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256689)
 * Hij Andrea,
 * I want to display the counter on two pages and maybe in a text widget.
 * I tried to put the code in the plugin ‘easy code placement’. This didn’t work.
 * Willem
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256741)
 * hi willem,
 * I’ve just tested the code into a template file and it works.
    I don’t know exactly
   how this easy code placement works, but probably there is something you are doing
   wrong..
 * maybe try to return the number instead of echoing
 *     ```
       $count_posts = wp_count_posts();
       $published_posts = $count_posts->publish;
       return $published_posts;
       ```
   
 * because that’s how a shortcode would expect to get the output.
 * then I don’t know if you also need to wrap the code into php tags
 *     ```
       <?php 
       code
       ?>
       ```
   
 * also, you might want to paste the code into notepad or any other basic text editor,
   and then copy it from there and paste it where you want. many times when you 
   copy and paste from a web page you also copy hidden characters which then break
   the code
 *  [wassereimer](https://wordpress.org/support/users/wassereimer/)
 * (@wassereimer)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256796)
 * [@piccart](https://wordpress.org/support/users/piccart/)
 * Hi piccart,
 * the Code you´ve posted above works fine with my Plugin.
 *     ```
       <?php
       $count_posts = wp_count_posts();
       $published_posts = $count_posts->publish;
       echo $published_posts;
       ?>
       ```
   
 * Willem said that the code `<?php echo count($pbytax_posts); ?>` doesn´t work –
   that´s correct. It only outputs a “0”. That´s the reason i´ve said to him that
   he should contact you – the Plugin Author. 🙂
 * [@willem](https://wordpress.org/support/users/willem/)
 * Hi Willem,
 * the Code above works fine. Do you tried the Tips from piccart?
 *  Thread Starter [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256832)
 * Hi Andrea,
 * Like you suggested, this is the solution:
 * <?php
    $count_posts = wp_count_posts(); $published_posts = $count_posts->publish;
   echo $published_posts; ?>
 * Do you know how I can make the font size bigger within this code?
 * Willem
    -  This reply was modified 9 years, 6 months ago by [Willem 2](https://wordpress.org/support/users/willem-2/).
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8256954)
 * ok great! 🙂
 * Willem, the output code seems to contain the html tag for code.. that’s why it
   is displayed smaller: it is styled as a code block.
    I guess this might be caused
   by the fact that you have copied and pasted my code from here, and in this way
   you also pasted some hidden html into the “easy code placement” box.
 * could you try to delete what you have and type it again manually instead of copy&
   paste?
 *  Thread Starter [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8257744)
 * Hi Andrea,
 * I followed your suggestion to type the code instead of copy and paste it. The
   size is still too small.
 * Willem
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8258012)
 * Hello Willem,
 * I’ve installed that plugin and did a test and I think I understood what’s the
   problem.
 * if you copy and paste the shortcode from the table in the main plugin page, it
   will copy the html around the shortcode too!
    so when you paste it, it will paste
   it as well, and that’s why then the output of the code is wrapped into that html.
 * try typing the shortcode manually, or you can click on the icon “paste as text”
   in the post content editor, before you actually paste it:
    ⌊paste as text screenshot⌉
 * this is something you should use as a general rule when you copy and paste into
   the post editor.
    and in general try to avoid copy&paste I’ve seen so many issues
   caused by copy&paste that is always one of the first things I check when debugging
   a problem.. 😉
 * what I do is to always paste into a basic text editor like notepad, which will
   then strip out all the extra html markup because it doesn’t understand it. then
   I click to copy again from the notepad and I paste the code where I need it. 
   😉
 * cheers!
    -  This reply was modified 9 years, 6 months ago by [piccart](https://wordpress.org/support/users/piccart/).
 *  Thread Starter [Willem 2](https://wordpress.org/support/users/willem-2/)
 * (@willem-2)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8258213)
 * Hi Andrea,
 * Yes, that was the problem! It’s resolved now. Thank you very very much!!!
 * I shall warn the developer of the plugin ‘easy code replacer’.
 * Willem
 *  Plugin Author [piccart](https://wordpress.org/support/users/piccart/)
 * (@piccart)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/#post-8259578)
 * perfect!
 * though that’s not actually an error nor a fault of the plugin developer.. it 
   is just normal behaviour when you copy and paste code from a web page or from
   a complex editor (like windows’ Word). in many cases the copy will copy the hidden
   html too.
 * it is more about knowing that copy&paste could do this kind of things, and paying
   attention when you copy&paste. 😉
 * cheers!

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/php-code-32/page/2/?output_format=md) 
[→](https://wordpress.org/support/topic/php-code-32/page/2/?output_format=md)

The topic ‘php code’ is closed to new replies.

 * ![](https://ps.w.org/wp-list-pages-by-custom-taxonomy/assets/icon-256x256.jpg?
   rev=1256692)
 * [WP LIST PAGES BY CUSTOM TAXONOMY](https://wordpress.org/plugins/wp-list-pages-by-custom-taxonomy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-list-pages-by-custom-taxonomy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-list-pages-by-custom-taxonomy/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-list-pages-by-custom-taxonomy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-list-pages-by-custom-taxonomy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-list-pages-by-custom-taxonomy/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)

 * 16 replies
 * 3 participants
 * Last reply from: [Willem 2](https://wordpress.org/support/users/willem-2/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/php-code-32/page/2/#post-8260009)
 * Status: resolved