Tag Info

Hot answers tagged

4

You can add a filter to 'loop_start', count how may posts you have and inject the needed number of "fake" posts that are intances of WP_Post not having a reference in DB. add_filter( 'loop_start', function( $query ) { $module = $query->post_count % 6; $to_fill = $module === 0 ? 0 : 6 - $module ; if ( (int) $query->post_count === 0 || ...


4

In the tutorial (Example 1), he has to declare the global $post so that he can access the post_parent from it. In a function like that, the $post is not a global variable unless he makes it so. In the codex (Example 2), it is declared global because the sample code is just a sample, explicitly trying to tell you that the $post variable is a global one. ...


4

Revisions to me are useless and just fills up your db with unnecessary "posts". It might be useful to others though. Revisions are created each time a post is revised/updated. This just holds an archive/copy of the post before it was updated, and gives the user an option to restore the specific post to an earlier time. This works exactly like any system ...


3

You could just rewind the query to loop through again: <?php rewind_posts(); ?> <?php while ( have_posts() ) : the_post(); ?> <p>Post Number: <?php the_ID(); ?></p> <?php endwhile; ?> THE LOOP


3

I suspect what you're trying to do is implement related posts, and you're using post meta to indicate which posts are related to the current post. So if I have a handbag, and there are 5 related products, the handbag product has post meta containing the IDs of those 5 products. While this sort of works, it doesn't scale, and it isn't performant. Instead ...


3

If I understand well, user having a special role in your site should: Be able to edit own posts in all statuses but 'publish' and not be able to publish them, just send for revision Be able to edit others posts only when pending, but not be able to publish them, just send for revision Never be able to delete other posts, no matter the status If so, it ...


2

If I understand you correctly, you just need to get all the ID's. The $wp_query global is available as the main query has already executed, so can just access the $posts property and from there get your post ID's. Something like this will do global $wp_query; $posts = $wp_query->posts; foreach ( $posts as $post ) { echo $post->ID; } If you need ...


1

Great Snippet available here from the guys at CSS-Tricks: $thumb_id = get_post_thumbnail_id(); $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true); $thumb_url = $thumb_url_array[0]; When I first tried this solution it kept throwing 'Missing Attachment' because I was referencing the post ID instead of the attachment ID. ...


1

You can trigger your web-service-calling code by using this: http://codex.wordpress.org/Plugin_API/Action_Reference/publish_post You can add a checkbox using this: http://codex.wordpress.org/Function_Reference/add_meta_box


1

The $post global variable is set by $wp_query->the_post() (WP_Post) inside the loop and is accessible during the loop. $post holds the post data from the current post. When you are inside the loop, you don't need to call the $post global, as it is already accessible. When you are outside the loop, and you need to access post data, you need to make use ...



Only top voted, non community-wiki answers of a minimum length are eligible