Extract post category except one category

You can simply loop over the categories that you don’t need. get_the_category() return an array of categories that the post belongs to. With that in mind, you can do the following: (Just remember to change 21 and 41 to your desired ID’s) $categories = get_the_category(); foreach ( $categories as $category ) { if( 21 === … Read more

Custom WordPress Excerpt within terms

I’ve used code like this, based (extremely) loosely on the plugin relevanssi: (in “functions.php”) // Roughly based on the relevanssi_do_excerpt() (https://wordpress.org/plugins/relevanssi/, GPLv2 or later), seriously simplified. function mytheme_search_context( $haystack, $needles, $len = 30 ) { $ret=””; $haystack = strip_tags(mytheme_strip_invisibles($haystack)); $haystack = trim( preg_replace( array( “/\n\r|\r\n|\n|\r/”, ‘/\s\s+/’, ‘/&.{1,30}?;/’ ), ‘ ‘, $haystack ) ); $words = … Read more

Metaboxes – why they don’t render php in expected manner?

The whole page/post/custom post type post screen is a big form. That means that whenever you hit “publish” on a post type edit screen, the whole form – and that means every content on the page – gets processed and WordPress executes everything. And that “everything” includes all kinds of hooks that you should use … Read more