simple wp_insert_post example

// Create post object $my_post = array(); $my_post[‘post_title’] = ‘My post’; $my_post[‘post_content’] = ‘This is my post.’; $my_post[‘post_status’] = ‘publish’; $my_post[‘post_author’] = 1; $my_post[‘post_category’] = array(0); // Insert the post into the database wp_insert_post( $my_post );” This works fine. You code is correct, but it is an problem in the form to send the $_POST … Read more

Rewrite custom post & taxonomy to share same URL path

(Revised on March 7th 2020 UTC) So sharing the same permalink path (or rewrite slug/base as in example.com/<rewrite slug>/<term slug> and example.com/<rewrite slug>/<post slug>) is possible, and here’s the (updated) code which enables you to share the exact same rewrite slug between a taxonomy and a post type: function wpse_358157_parse_request( $wp ) { $path=”about-us/video-center”; // … Read more

Remove Posts Quick Edit link for specific user role? WP 3.3

Based on this answer, yours was easy: add_filter(‘post_row_actions’, ‘wpse_49800_qe_download_link’, 10, 2); add_filter(‘page_row_actions’, ‘wpse_49800_qe_download_link’, 10, 2); // for Custom Post Types // add_filter(‘cpt_name_row_actions’, ‘wpse_49800_qe_download_link’, 10, 2); function wpse_49800_qe_download_link($actions, $post) { unset($actions[‘inline hide-if-no-js’],$actions[‘trash’]); return $actions; } Notice that you don’t mention the ‘Trash’, so it’s being removed as well. Plugin of interest Adminimize is able to hide … Read more

Insert custom div between posts

You can check your position within the loop using the current_post var of the $wp_query object, and insert markup at a specific spot or at some interval. A simple example: while( have_posts() ): the_post(); the_title(); the_excerpt(); // if current_post is 1, insert the div // note that current_post starts at 0, // so this will … Read more

Post content being duplicated by the_content();

The problem is still present, but I’ve found a workaround for now. When I replaced echo apply_filters(‘the_content’, get_post_field(‘post_content’, $post_id)) with echo wpautop( get_the_content() ), it worked. I also stopped using the variable $post since I wasn’t accessing the global post variable. So that makes my code look like so: $state_posts = array(); while ($query->have_posts()) { … Read more

How to let custom post type posts show in standard post archive (like in homepage)?

Hooking the following function with the pre_get_posts filter will add one or more CPTs to the regular archive pages: function wpse94041_cpts_in_archives( $query ) { if( is_category() || is_tag() ) { // more conditional tags possible, if applicable $query->set( ‘post_type’, array( ‘post’, ‘tutorial’ // add as many CPTs to this array as you like )); } … Read more

One comment per user email per post

Try this, the code below will generate every comment by the $current_user->user_email for the author_email, if the $usercomment return something, then there is a comment by the current user so echo “thank you”, but if it’s not return anything output the form. global $current_user,$post; $usercomment = get_comments(array(‘author_email’ => $current_user->user_email, ‘post_id’ => $post->ID)); if($usercomment) { echo … Read more

Show number of posts AND number on current page

This should work, but I haven’t tested it: global $wp_query; $page = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; $ppp = get_query_var(‘posts_per_page’); $end = $ppp * $page; $start = $end – $ppp + 1; $total = $wp_query->found_posts; echo “Showing posts $start through $end of $total total.”;

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