confused about wp_list_pages() function – how to display selected top pages with all their subpages

When you use include parameter of wp_list_pages you are basically telling it to only include these certain Pages in the list. you should use exclude_tree instead, when using this parameter it will exclude a parent and all of that parent’s child Pages. so something like: $top_pages_to_exclude=”1″; // the top page to be excluded ID, you … Read more

Wp Enviroment problem with included file

The error indicates that your file “floater.php” is being called outside of a WordPress generated page. Add this to the top of the file to be able to use WordPress functions. EDIT: See Brian Fegter response on using the server path for your include. if ( !function_exists( ‘get_bloginfo’ ) ) require( ‘../../../wp-blog-header.php’ ); // check … Read more

Post’s ID pattern?

Each auto-draft gets its own ID, each revision, each nav item, page, custom post type … The actual ID of a post should be irrelevant, this is really just needed for the database and ugly permalinks. You cannot get the last 30 items by inspecting the post ID only. Install a REST API on the … Read more

php include not working in custom page

WordPress has its own connection class, which can be used trough the $wpdb object. Is there a particular reason to use direct queries to the db, instead the wordpress functions (get_posts, get_post_meta, get_option)? Keep in mind that by doing this, you loose a lot of the wordpress tools, such as cache, filters, etc…

Conditionally include files in functions.php?

Use WordPress’ conditional tags, global variables, defines, class checks and the like. For instance like so: <?php // load helper functions – always require_once get_stylesheet_directory() . ‘/inc/helper-functions.php’; // load admin functions – for back-end only if ( is_admin() ) require_once get_stylesheet_directory() . ‘/inc/admin-functions.php’; // load WooCommerce functions – when WooCommerce is active if ( in_array( … Read more