access wordpress admin setting in php

In the wordpress admin you can set “Blog pages show at most” under Settings>Reading

Is it possible to get the value of that to use in my theme? Could I also alter its default setting from my theme pages without going trough the admin? (set it to 20 for example)

Read More

Thanks dor your help guys!

Related posts

Leave a Reply

2 comments

  1. I think you’re interested in get_option( 'posts_per_page' );, which basically tells you what to look for in the wp_options table. You can find details here.

    Also, if you want to change this option, you can do it with this.

  2. The option you are looking for is posts_per_page and you get it like:

    $posts_per_page = get_option("posts_per_page");
    

    You could alter the default setting conditionally by using the option filter on your theme page like so:

    <?php 
        function override_posts_per_page($originalValue){
            if(/* put your page conditional here */)
                return 20;
            else
                return $originalValue;
        }
        add_filter('option_posts_per_page', 'override_posts_per_page', 10, 1);
    ?>