Tag Info

Hot answers tagged

3

Hopefully I've understood your question correctly, and I hope the code below helps. First you must add a metabox to hold the option that you wish to add to each Post, and the my_add_sticky_metabox() function will do this, in conjunction with the add_meta_boxes action hook. At this stage you are not actually printing anything, but rather telling WordPress ...


2

Out of curiosity, I played around with static SQL queries and this one seemed to work: SELECT r.post_author, r.ID, r.post_title FROM ( SELECT p.post_author, p.ID, p.post_title FROM wp_posts p INNER JOIN wp_term_relationships tr ON ( p.ID = tr.object_id ) WHERE p.post_date < '2015-02-05 00:00:00' AND p.ID NOT IN (10,20) ...


1

With what you are asking, it is really difficult to come up with some performant easy way that is also reliable. As @birgire already stated, his solution is not reliable, but from tests, it seem to be the fastest clocking in at 2 db queries in about 0.015s average. From a quick discussion between @birgire and me in comments to his answer, I've decided to ...


1

You can do this with Sticky Posts feature in WordPress. When you make a post sticky, it shows up above your new posts. As name suggests, that particular post will stick at top, first in the row for as long as you want. Sticky Posts is a feature introduced with Version 2.7. A check box is included on the Administration > Posts > Add New Screen (In the ...


1

Give this a try. It replaces query_posts(), which you should never use (it kills unicorns) with WP_Query. Basically it first queries your sticky posts and then, if there were less than your required 3 posts, it will perform another query for the relavent number of posts. /** Grab the sticky post ID's */ $sticky = get_option('sticky_posts'); /** Query the ...


1

Saving the date in post meta is a slightly more sane approach, the post_date column was not designed with your use case in mind. You may get weird results with dates before the Unix epoch (January 1, 1970). Then it's just a simple meta_query to load posts between dates, no filter necessary. $start = '1900-01-01'; $end = '1949-12-31'; $args = array( ...


1

Instead of event date and event time, make the meta keys start time and end time and save them both as timestamps, then events will order correctly when sorted by start time key only.


1

Regions and cities fit perfectly in the concept of taxonomy: a way to group things (i.e. posts). And not so much in the concept of meta data. I strongly recommend to use custom taxonomies for that instead of custom meta fields. You will gain in performance and you will have a better data relationship management. Additionally, you should stop using ...



Only top voted, non community-wiki answers of a minimum length are eligible