Limit function to specific post category

You should check for category posts to modify content. Specify category ID (integer), name or slug (string), or an array of these in in_category check. function my_image_tag( $html, $id , $alt, $title ) { if ( in_category( ‘1’ ) ) { $html = “<div class=”my-class”>” . $html . “</div>”; } return $html; } add_filter( ‘get_image_tag’, … Read more

Fetch posts from current week (Sunday to Saturday)

You can try: ‘date_query’ => array( array( ‘year’ => date( ‘Y’ ), ‘week’ => strftime( ‘%U’ ), ), ), where %U is: Week number of the given year, starting with the first Sunday as the first week or ‘date_query’ => array( array( ‘after’ => strtotime( ‘last Sunday’ ), ), ),

Redirect before post page

The determination to redirect needs to be made prior to headers being sent to the browser. Otherwise you risk PHP warnings (i.e. errors) when the page is rendered. This makes the timing of the use of wp_redirect() incorrect in the other answers. (The function is right, it’s just used incorrectly.) If you are going to … Read more

if custom post type exist

You typed “mobiles” when you said you wanted to check for post type “mobile”. So simply remove the s ;). <? if( post_type_exists( ‘mobiles’ ) ) { echo ‘The Products post type exists’;} ?> Should be: <? if( post_type_exists( ‘mobile’ ) ) { echo ‘The Mobile post type exists’;} ?> If it’s still not working, … Read more

Edit menu item title from edit page/post

Whenever you add a new item to WordPress Menu ( Appearance -> Menu ) it creates a new Post of Post Type nav_menu_item and gets assigned a post meta called _menu_item_object_id with the main Post ID. For example, if I create a page called “Home” it gets assigned a Post ID of 2. Now, when … Read more

How to update serialized post meta?

You must read custom field themeOps first, update index option3 in array and then save/update whole array. $kisiArray = get_post_meta( $post_id, ‘themeOps’ ); $kisiArray[‘option3’] = ‘peach’; update_post_meta( $post_id, ‘themeOps’, $kisiArray ); Update (sort by custom field) $args = array( ‘post_type’ => ‘post’, ‘meta_key’ => ‘themeOps_option3’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ); $query = new … Read more