wp_insert_posts add title with count of posts plus one

The problem was that I can’t get wp_count of my custom post type. The result was that I got nothing. I found this solution $args = array( ‘post_type’ => ‘orders’ ); $count = new WP_Query( $args ); $orders = $count->found_posts +1; After this I insert my post

Future post ID not showing

The problem is that you are using get_the_ID() outside the loop. Also, you are getting the global $post overriding the $post object passed to the function and then overriding it again with get_post() function. As you have already the $post object which status has changed, you need nothing of the get_the_ID, get_post or global $post. … Read more

How to display featured image without it appearing in post?

You can set the featured image on the post. That featured image will not be on the post content. If it’s showing on the post it’s because your template is calling has_thumbnail() on the single.php or content-single.php. If you need more help, please past the single.php or content-single.php code, or say which theme you are … Read more

Email Post Attachment on wp_insert_post Action

After asking this question in several places and not getting a solution, I found the solution this morning myself. Instead of hooking the function send_email_on_pending_post_creation to the “wp_insert_post” action, you need to hook it to the “add_attachment” action which occurs AFTER the post is inserted and when the attachment is added to the post. You … Read more

Inserting custom data to the_post() during loop

Yep, it’s not very common, but perfectly viable and nifty technique. After the posts are retrieved in WP_Query they are passed through the_posts filter like this (where $this is WP_Query instance): $this->posts = apply_filters_ref_array( ‘the_posts’, array( $this->posts, &$this ) ); You just loop through array and assign the extra data you need to objects. Don’t … Read more

Posts not showing on page

There aren’t any errors in your code. I’m able to copy / paste it into functions.php and return 3 posts categorized under “testimonials” without issue. By default this WP_Query will retrieve only ‘post’ matches so if you are using pages or a custom post type you’ll need to specify that in your query args as: … Read more

Driving a random quote like functionality with database

From your comments I don’t really know why you should not make use of custom post types and custom fields. So what is you have extra flexibility from the above. IMHO, extra flexibility is always a plus when attempting something like this. The other plus points here are that you don’t have to make use … Read more