Are Post IDs Unique Across all Post Types?
All post types are stored in the same posts table, so they have to use different post IDs. That was always the case, since the the post type page was introduced 2005 with version 1.5.
All post types are stored in the same posts table, so they have to use different post IDs. That was always the case, since the the post type page was introduced 2005 with version 1.5.
hey just look in code and it also support fourth parameter post global $post; the_title_attribute(array(‘post’=>$post));//post object or global $post; the_title_attribute(array(‘post’=>$post->ID));//post id so you can use it like <a href=”https://wordpress.stackexchange.com/questions/111931/<?php echo get_permalink($id); ?>” title=”<?php the_title_attribute(array(‘post’=>$id)); ?>”> //where $id is post id Important Link the_title_attribute
The following query retrieves the oldest post of a specified user/author: $user_id = 42; // or whatever it is $args = array( ‘posts_per_page’ => 1, ‘post_status’ => ‘publish’, ‘author’ => $user_id, ‘orderby’ => ‘date’, ‘order’ => ‘ASC’, ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { $first_post->the_post(); // Now you can use `the_title();` etc. wp_reset_postdata(); } … Read more
Dont use query_posts or WP_Query if you need it in the main loop. Dont ever use query_posts anyway. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $current_id = get_the_ID(); ?> <?php echo $current_id ?> <h1><?php the_field(‘titleFart’, $current_id); ?></h1> <?php endwhile; // end of the loop. ?> <?php endif; ?> … Read more
Are you writing a template? A filter in functions.php or a plugin? A straightforward method could be using get_post_gallery with the second argument set to false, so that it return the object rather than the html. if ( get_post_gallery() ) : //Get the gallery object $gallery = get_post_gallery( get_the_ID(), false ); //Form an array with … Read more
you should use it: <?php get_comment( $id, $output ); ?> Return comment_ID (integer) The comment ID comment_post_ID (integer) The post ID of the associated post comment_author (string) The comment author’s name comment_author_email (string) The comment author’s email comment_author_url (string) The comment author’s webpage comment_author_IP (string) The comment author’s IP comment_date (string) The datetime of the … Read more
Try this… add_action(‘post_updated’, ‘myfunction’); function myfunction( $post_id ) { global $post; if (!file_exists(“/www/foo/blog/wp-content/uploads/” . $post_id)) { mkdir(“/www/foo/blog/wp-content/uploads/” . $post_id, 0777); } } NOTE: Change from save_posts to post_updated which will stop the duplicate issue as it fires on “publish” only and not every time you hit add new or update etc. NOTE: I verified this … Read more
$cat_id = get_queried_object_id(); – it’s that simple!
Showing random content / pictures from earlier posts in a sticky post?
Do you have custom post type videos? if not change videos to post add_meta_box( ‘my-meta-box-id’, ‘Enter Video ID’, ‘cd_meta_box_cb’, ‘post’, ‘normal’, ‘high’ ); Your code is fine but you are not saving the video type select box you just updated the id input field. Place this code in add_action(‘save_post’, ‘cd_meta_box_save’); if( isset( $_POST[‘my_meta_box_text’] ) && … Read more