Disallow Same Post Title

Main Code Please check the auxiliary code after this block /* * Prevent Duplicated Titles * */ if( is_admin() ) // check if we are in the administrative area { add_action( ‘save_post’, ‘wpse_54258_check_for_duplicate_title’, 11, 2 ); add_action( ‘admin_head-post.php’, ‘wpse_54258_check_for_notice’ ); } /* * Checks for more than one post with the same title * * … Read more

Category checkbox list tree changes when editing a post

Category-list uses the function wp_terms_checklist() in wp-admin/includes/template.php on row 90. The parameter “checked_ontop” is set to true. So the checked checkboxes will be on top. This is only happening when editing a post, when I add a new one everything is fine and dandy Thats because when you create a post, none of the categories … Read more

How to cache a shortcode functions output?

You might have a look at the WordPress Transient API. You should be able to store your shortcode output $total_network with set_transient( ‘my_shortcode_cache’, $total_network, WEEK_IN_SECONDS ); where WEEK_IN_SECONDS is a built in constant equal to 604800. You can then fetch it with: get_transient( ‘my_shortcode_cache’ ); If you need it to work network wide there exists … Read more

get comments and get posts in loop

get_comments accepts an array of arguments, you are passing an integer. If you want to retrieve all comments for a post use: get_comments( array(‘post_id’ => $post->ID, ‘status’ => ‘approve’) ); To get an already formatted comment list, is easier use the wp_list_comments() function, instead of another foreach cycle (code from codex): echo ‘<ol class=”commentlist”>’; //Gather … Read more

How do I create a link that will always show the latest post?

If I understand well you want to show the last post (one post) from one of the 3 post types you have, using a dynamic url like http://example.com/latest. First of all lets add a filter to ‘do_parse_request’ filter: add_filter( ‘do_parse_request’, function( $bool, WP $wp ) { $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), “https://wordpress.stackexchange.com/” ); … Read more

When and Where is `global $post` Set and Available?

Global $post var is set by WP::register_globals() method. It is called by WP::main() method, on its turn called by wp() function that is called when wp-blog-header.php is loaded. If you look at the graph @Rarst built, on the left, you can see where wp() function is called. In terms of hooks, global post variable is … Read more

WordPress REST Create Post of Custom Type

Make sure your post type is shown in the REST API. $args = array( //* Use whatever other args you want ‘show_in_rest’ => true, ‘rest_base’ => ‘myslug’, ‘rest_controller_class’ => ‘WP_REST_Posts_Controller’, ); register_post_type( ‘myslug’, $args ); The endpoint to create a post would then be http://example.com/wp-json/wp/v2/myslug. Edit: The above is all that’s needed for a custom … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)