Display Post Meta in Header
Use get_the_ID(), the post object is not set up completely on wp_head(): if ( is_singular() ) $post = get_post( get_the_ID() );
Use get_the_ID(), the post object is not set up completely on wp_head(): if ( is_singular() ) $post = get_post( get_the_ID() );
Presumably, these are widgets that you are writing. If so, basic PHP class methods should do it– set a static class property to hold your “overlap” data. class Foo extends WP_Widget { static $overlap; /*constructs etc*/ function __construct($id = ‘twidg’, $descr=”Test Widget”, $opts = array()) { $widget_opts = array(); parent::__construct($id,$descr,$widget_opts); /*do stuff*/ } function widget() … Read more
The default search is handled by WP_Query mostly by a method called parse_search(), which is triggered by the s parameter. You can search the source of WP_Query for is_search and piece together a few other bits and pieces. Or you can just create a query… $s = new WP_Query(array(‘s’ => ‘test’)); … dump the SQL… … Read more
It doesn’t recognize WP, because as far as PHP is concerned it’s not. It’s just a PHP file that happens to be in one of the folders related to WordPress. You need to explicitly include WordPress core into it to have access to its functionality. However such custom handlers are notoriously fragile. It would be … Read more
After asking around and looking for alternatives, I came up with a working solution that works in the web frontend and in the Android/iOS XML-RPC based apps. This is the filter. add_filter(‘wp_insert_post_data’, array($this, ‘save_content2’), 9, 2); I am pretty sure it is called before the content_save_pre filter. It allows direct access to the post fields … Read more
here is the full code to force change theme by a reserved wordpress parameter add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); function my_pre_get_posts($wp_query) { global $wpdb; // Confirm request is main query if(!$wp_query->is_main_query()) { return; } // Get post name from query $post_name = $wp_query->get(‘pagename’); // Get post type from database $post_type = $wpdb->get_var( $wpdb->prepare( ‘SELECT post_type FROM … Read more
Don’t use globals, but if you must use them you should explicitly declare them as such. WordPress includes theme files from functions therefor a $test = 1; will be evaluated in the context of the function and the variable $test will be implicitly declared in the context of the function but not as a global.
You cannot define something outside a function and then simply try to use it inside the function without calling it into the function. This is basic PHP and how functions work in general. You need to pass that specific something to the function or define that something inside the function or use a method to … Read more
It’s possible to capture the $post_id using a combination of wp_get_referer() and url_to_postid() then reset the $post using setup_postdata. That should work easy enough for the front-end. But on the admin side we’ll need to pull the query with parse_url and grab the ID using parse_str. For good measure we should double check if we’re … Read more
This is that classic question, do you have 6 eggs or half a dozen, and frankly, it doesn’t actually matter. It is however better to use get_comments_number() because the post object is retrieved from the $GLOBALS[‘post’] global which is set by the_post() inside the loop the post object is validated through WP_Post (through get_post()) the … Read more