Insert all post IDs in new database table
Like so: INSERT INTO $mytable (post_id) SELECT ID FROM $wpdb->posts as posts LEFT JOIN $mytable as dup_check ON dup_check.post_id = posts.ID WHERE dup_check.post_id IS NULL;
Like so: INSERT INTO $mytable (post_id) SELECT ID FROM $wpdb->posts as posts LEFT JOIN $mytable as dup_check ON dup_check.post_id = posts.ID WHERE dup_check.post_id IS NULL;
There is a post_limits hook that you can use for this purpose exactly: // in homepage show 6 posts add_filter(‘post_limits’, ‘homepage_limits’ ); function homepage_limits( $limits ) { if(is_home() ) { return ‘LIMIT 0, 6’;; } return $limits; }
This should do the trick: <?php $day = date(‘Ymd’); query_posts(“m=$day”); The query arg ‘m’ for WordPress will be interpreted as a year if it is four characters long, a month if 6, and a date if 8. EDIT You should probably add in the original query string just in case you’re writing enough to need … Read more
query_posts with a custom post type, a meta_query and sorting by post date?
Querying posts with meta value that begins with a certain pattern
$songQuery = new WP_Query(‘meta_query’ => array( array( ‘key’ => ‘song-id’, ‘value’ => ‘song id value here’, ‘compare’ => ‘=’ ) )); You can use above code to query with custom field then use loop to get the contents.
For both loops move <a href=”https://wordpress.stackexchange.com/questions/67673/<?php the_permalink(); ?>”> To after while ( $the_query->have_posts() ) : $the_query->the_post(); the_permalink() is template tag and as such generates what it does, based on global $post variable. In your custom loop it doesn’t contain the post you want until after $the_query->the_post() call.
For anyone who may have a similar need, I solved this the following way (on authors.php): First I get the author ID: $author = get_user_by( ‘slug’, get_query_var( ‘author_name’ ) ); // ID is accessed this way: $author_id = $author->ID; I then created a custom query: $query = ” SELECT p.* FROM $wpdb->postmeta m JOIN $wpdb->posts … Read more
I found a partial workaround. Since the query object in the index.php is the right one I transferred it using serialize to template of choice, in this case category-video.php. In index.php i put on top <?php $s = serialize($wp_query); file_put_contents(‘query’,$s); ?> and in category-video.php I put <?php $u = file_get_contents(‘query’); $wp_the_query = unserialize($u); ?> It’s … Read more
Since I couldn’t find the way to grab the custom post’s title and add it to the sorting/ordering by meta_key, I edited my custom post type to include a hidden field that grabs the title of the post and sets it as a custom meta value when the user adds a new custom post. So, … Read more