Tag Info

New answers tagged

1

More complex way I use it this way (I'm usually doing one page design, however the method of loading pages is still same). Fo Theme options, I'm using Option tree plugin where my clients could just checkbox which pages should appear there (it's passed by it's ID) and than I load it into the script. <?php // loading pages which should appear by option ...


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 ...


0

You might try this but using query_posts() is strongly discouraged: query_posts( array( 'post_type' => 'hotel', 'post_per_page' => '500', 'order' => 'ASC', 'meta_key' => 'hotel-city', 'orderby' => 'meta_value', 'meta_query' => array( array('key' => 'hotel-region', ...


0

A better method for what you are trying to achieve This answer is not about the php error you are getting. You need these classes for styling your website right? Put the following code in your functions.php // A better body class function condensed_body_class($classes) { global $post; // add a class for the name of the page - later might want to ...


0

Keep in mind this will only work if you're on a single page or post, because when you're displaying the output of a loop, you don't yet have a post until you've started the loop (or, you might have the first post in the loop, but either way that's not what you'd want to set a body ID for). I'd recommend wrapping this ID with two conditionals: <?php ...


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.


0

I'm not sure exactly how you want 'term_single' formatted, but you can amend the below as required if it's not quite what you are looking for. I'd also suggest not using the name $posts for your array, as I believe that WP has a global of the same name, so it could cause funkyness that is undesirable. Finally, as you were in The Loop you can use simple ...


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( ...


0

Well, WP may be suppressing your filter. Per the WP Codex on posts_where @: http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where Certain functions which retrieve posts do not run filters, so the posts_where filter functions you attach will not modify the query. To overcome this, set suppress_filters to false in the argument array passed to ...


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 ...


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 ...


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 ...


0

Another solution that seams to work is explained:here Adding the filter before the query: function filter_authors($groupby) { global $wpdb; $groupby = " {$wpdb->posts}.post_author"; return $groupby; } add_filter('posts_groupby','filter_authors'); And not forgetting to remove it afterwards: remove_filter('posts_groupby','filter_authors'); This ...


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

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 ...


0

You really should try to avoid using query_posts if at all possible. See When to Use WP Query vs Query Posts vs Get Posts Here is a pass through a loop using WP_Query: $args = array( 'tax_query' => array( array( 'taxonomy' => 'region', 'field' => 'id', 'terms' => $region_id ) ) ); ...


0

You can use like this <?php $id = get_the_ID(); $squery = new WP_Query( array( 'post_type' => 'lyrics', 'posts_per_page' => -1, 'meta_key' => 'your_meta_key', 'meta_value' => $id, ) ); if( $squery->have_posts() ) : ?> <?php while( $squery->have_posts() ) : $squery->the_post(); ?> <h1><?php ...


0

This all depends on what you're actually saving in your post meta. If you're actually saving the ID you could create a secondary query on your single-post_type.php page. <?php if( have_posts() ) : ?> <?php while( have_posts() ) : the_post(); $cpt2_meta = get_post_meta( $post->ID, '_meta_name', true ); // Get out Post ...



Top 50 recent answers are included