Articles of posts

Having pages after specifying post_type post

I want to loop through all posts in category 4,but why is there still pages in the result after specifying post_type post? $homeNeWs = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 6, ‘cat’ => 4 )); while ($homeNeWs->have_posts()) : $homeNeWs->the_post(); <h3><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h3> <?php endwhile; wp_reset_postdata(); ?> I did add a function […]

When moving a WordPress installation to a new server, why do I have to update each post before content shows?

The site URL (www.example.com) hasn’t changed. So I exported the wp_posts table from my old shared hosting server database and imported it into a new WordPress installation on my new dedicated server. I set the permalink structure in the WordPress installation on the new server to be http://www.example.com/%postname%/, the same as on the old shared […]

Creating an admin meta box to save post as pending

The workflow when using WordPress to change a draft post to pending involves several clicks and button presses, especially on mobile So to simplify my process I would like to create a meta box that just has a save as pending button. ( I have a plugin that takes pending posts and publishes them to […]

Retrieve post in AJAX Callback

I have a JS file that triggers a PHP callback file. The PHP file is supposed to work on the Post that is currently opened (wp-admin/post.php). I do not want the JS file to pass the post id though since that could be tampered with. Is there any way to repopulate the global $post or […]

trigger email when post is published by someone a user follows

I’m trying to send an email to all users who are following a certain post author when they publish a post. I have this function below, but does not seem to work. a few notes the meta value = ‘following’ is an array that contains the authors user follows. function followerPost_notification($post_id) { $post = get_post($post_id); […]

Grab ID from post from plugin and use it to create an object

I want to create an object and set ID for this object like $p = new Product(87); I have this code within a plugin and I want to grab the ID of the custom post being showed: function getPostId(){ global $wp_query; global $pid; $pid = $wp_query->post->ID; echo ‘pid=’ . $pid; //returns 87 } add_action(‘wp_head’,’getPostId’); //I […]

I want to show my post for limited time, how is it possible?

I want to make one website like a newspaper, so i want to show my daily post for one day or limited time, after one day previous post will go to archive and no longer show on web page, how is it possible?

Conflict array_splice on loop and query in widget

I am using the function array_slice to insert two post within the loop in the index. function insert_post_wpse_96347($posts) { global $wp_query; $args = array(‘meta_key’ => ‘Caja’, ‘meta_value’ => array(‘UNO’,’DOS’), ‘post__not_in’ => get_option(“sticky_posts”), ‘posts_per_page’ => ‘2’,’suppress_filters’=>true); if (is_main_query() && is_home() && 0 == get_query_var(‘paged’)) { $p2insert = new WP_Query($args); $insert_at = 0; if (!empty($p2insert->posts)) { array_splice($posts,$insert_at,0,$p2insert->posts); […]

Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )

I was learning from the WordPress codex about global variables and after var_dump($post) I found out that $post has a property called comment_count I was wondering whether I can directly use $post->comment_count instead of get_comments_number( $post_id ) inside the loop? Or does it have any disadvantage?

How to display post list in a table layout (multiple queries in single loop)

I am setting up an events page for my website. This page is using a loop to display a list of acts performing at different venues month-by-month. When a viewer comes to the page, they use a simple form to select the month, and when submitted this return the relevant data. At the moment the […]