How to update page status from publish to draft and draft to publish
A faster solution is: $post = array( ‘ID’ => $post_id, ‘post_status’ => $status ); wp_update_post($post); This way you don’t have to get the post.
A faster solution is: $post = array( ‘ID’ => $post_id, ‘post_status’ => $status ); wp_update_post($post); This way you don’t have to get the post.
The problem comes from the fact that, in order to display pages and their hierarchy, WP has to load all of them and then build the tree in memory. So, you are saved if you can convert most of those pages into one or several non-hierarchical custom post types. The permalink structure can be emulated.
The WP_Query object contains a max_num_pages field which contains how many pages of posts there are. You can compare the current page number with it. (This is how get_next_posts_link() does it.) global $wp_query; $current_page = $wp_query->get( ‘paged’ ); if ( ! $current_page ) { $current_page = 1; } if ( $current_page == $wp_query->max_num_pages ) { … Read more
You can use is_page_template to check if you template is being used and load your scripts based on that ex: Add this code to your functions.php: add_action(‘wp_enqueue_scripts’,’Load_Template_Scripts_wpa83855′); function Load_Template_Scripts_wpa83855(){ if ( is_page_template(‘custom-page.php’) ) { wp_enqueue_script(‘my-script’, ‘path/to/script.js’); } }
You already got something like this built in: Revisions. // Define the nr of saved revisions in your wp-config.php define( ‘WP_POST_REVISIONS’, 30 ); You can simply grab them by calling get_posts() with a post_type of revision. To show the difference between two revisions simply use wp_text_diff(). // Example $revisions = get_posts( array( ‘post_type’ => ‘revision’ … Read more
The following 2 filters allow you to hook into when WordPress checks the slug and are found in the function wp_unique_post_slug() in the wp-includes/post.php file. There are 2 filters, one for hierarchical posts and one for non-hierarchical. The hierarchical filter provides the ID for the post parent so if the $post_parent is 0, you know … Read more
Pages do have Custom Fields enabled by default on WordPress. If you’re not seeing them on the “New/Edit Page” page, then check the “Screen Options” pull down tab on the upper right corner of your Dashboard. See if “custom fields” is checked.
functions.php is processed way before you can know which page is being loaded. Instead of assigning value to variable put your code into function and use that function in page.php template.
When Working with pages you can select a parent page and that value is saved as the parent page id number in the child page’s post_parent field in the database. In your case, you are using a custom post type so you would need to create your own metabox for the parent page; something like: … Read more
The parameter to insert a custom slug is: ‘post_name’ => ‘my-custom-slug’ Not post_slug as one would think! 🙂