On Category page, How can I get the category ID?
$cat_id = get_queried_object_id(); – it’s that simple!
$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
Actually, wordpress stores the media library files also as a post format. so you can follow this way to get your attachment media file and their id’s. Hope this will help you. function get_images_from_media_library() { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ =>’image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => 5, ‘orderby’ => ‘rand’ ); $query_images = … Read more
You need to set the ID for the post_title and post_name. You have many approaches. Typically your approach would be to use a filter in WordPress. The best I can say would be wp_insert_post_data and use the second parameter of this filter to get the post id and return the first parameter with the modified … Read more
Use it like this : <div id=”page” class=”hfeed site”> <?php do_action( ‘before’ ); ?> <?php $page_id = ( ‘page’ == get_option( ‘show_on_front’ ) ? get_option( ‘page_for_posts’ ) : get_the_ID ); $banner = get_post_meta( $page_id, ‘banner’, true ); if (is_front_page() || $banner == ”) { ?> <header id=”masthead” class=”site-header” role=”banner”> <?php } else { ?> <header … Read more
In your admin, go to Posts > Tags and then click edit for the tag you’re after – the URL in your browser address bar will look like: http://example.com/wp-admin/edit-tags.php?action=edit&taxonomy=post_tag&tag_ID=X&post_type=post See the part where tag_ID=X – that X is your tag ID.
Figured it out. use is_home() to detect if its the posts archive page. kind of counter-intuitive because i always thought that function was to determine if it’s the homepage, found out there’s a is_front_page() for that.
wp_set_object_terms Works better with term slug instead of term id so change this line: $cat = array($category->term_id); to: $cat = array($category->slug);
On that page $post->ID returns the ID of first blog post for given page. That is how it works. $post is set to the first post in the Loop. On single posts and pages that is the same as the post or page. On archive pages it is the first post in the result set. … Read more