Adding JS functionality to the Publish button in wp-admin/post.php

Solved it by using a modal box instead of metabox, forcing the users to finish editing the plugin data, before submitting the regular changes to WP. //add_action( ‘add_meta_boxes’, array( $this, ‘add_custom_metabox’ ) ); add_action( ‘media_buttons_context’, array($this, ‘add_custom_media_buttons’ ) ); add_action( ‘admin_footer’, array($this, ‘add_esm_edit’ ) ); These were the lines that were added to the __construct(). … Read more

Get latest post from categories

Ok you can use a foreach loop to return the latest post from each category. Here is how you should do that. <?php $postids = array(); $catids = array( 1, 2, 3 ); // add category ids here. foreach ( $catids as $catid ) { $my_query = new WP_Query( array( ‘cat’ => $catid, ‘ignore_sticky_posts’ => … Read more

How do I link a Post Type to a Template in Masterplan?

I have never used Masterplan nor Masterpress, however as far as the template hierarchy is concerned, it seems to be no different from the standard WordPress way of dealing with it – See Masterpress Docs I assume that if your (Custom) Post Type is correctly registered through Masterpress interface, it should be registered in WordPress. … Read more

How to compare post tags?

Working off the assumption that you’re already on Post One, and want to add Post Two below it, as a “Related Posts” type feature, you can use a standard WordPress function to get an array of One’s tags, then do a query to grab and display posts with tags that match. //get just the IDs … Read more

Retrieving posts by their date and category

Please try the following code: Following code has to be added in shortcode function global $wpdb; $start .= $attr[‘godina’] . “-09-01”; $end .= $attr[‘godina’] + 1 . “-08-31”; $cat = $attr[‘cat’]; //$cat must be category name. $cat_term_id=get_term_by(‘name’, $cat, ‘category’); $term_id=$cat_term_id->term_id; $query = array( ‘post_type’ => ‘post’, ‘tax_query’ => array(array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, … Read more

Accessing Post ID Within Loop

The problem probably comes from whenever a $post has no terms set. You need to set $brand = array() outside your IF statement, add it just under get_the_terms(). At that point it also wouldn’t hurt to wrap your switch statement in a if( ! empty( $brand ) ) { Another problem I see with this … Read more

Get x recent posts by author?

The function you are using, get_most_recent_post_of_user, won’t work as it only retrieves the latest post from the author. It cannot retieve a list of posts Walks through each of a user’s blogs to find the post with the most recent post_date_gmt. You will most probably be better of using either WP_Query or get_posts to achieve … Read more

Use posts_where to exclude posts ids from wp_query

Instead of using posts_where it is a better idea to use pre_get_posts filter. Here is the code I end up implementing: add_filter( ‘pre_get_posts’, ‘hide_unwanted_posts_filter’ ); function hide_unwanted_posts_filter( $query ) { global $current_user; get_currentuserinfo(); $user_id = $current_user->ID; $key = ‘unwanted_posts’; $unwanted_posts = get_user_meta($user_id,$key,true); if(is_user_logged_in() && !empty($unwanted_posts) && !$query->is_admin) { $query->set(‘post__not_in’, $unwanted_posts ); // id of page … Read more