Exclude posts with specific meta_value while sorting by a separate meta_value

You code may be $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘posts_per_page’ => ’50’, ‘meta_key’ => ‘release_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘undetermined_date_toggle’, ‘value’ => ‘true’, ) ), ‘paged’ => $paged ); $the_query = new WP_Query( $args ); this code show only those posts which … Read more

Single.php Active Category Class

As vancoder notes, a post can have multiple categories and the following code highlights each category, as well as the current month for the post. Add to your theme’s functions.php. // Generate active class for categories when viewing single posts // Props to Sam Nabi http://samnabi.com/blog/highlight-the-current-category-for-single-posts-in-wordpress function singlePostActiveCat ($CatText) { global $post; if (is_singular()) { … Read more

Trying to put an array into ‘post__in’ => array() query not working

You need to explode the string you obtain from $_GET[‘ids’] into an array, at the moment you a parsing a to string post__in rather than an array of IDs. Try $purchaseprodid = isset($_GET[‘ids’]) ? explode(‘,’,$_GET[‘ids’]) : array(); However, you can sometimes run into difficulties using $_GET with WordPress, it’s better to use the API provided … Read more

How to update all post at once?

Try this out: /* Plugin Name: Post Bulk Update Description: Updates certain fields of my posts at once. On Activation. Awesome Author: Me. I did it */ add_action(‘init’,’post_bulk_update’); function post_bulk_update(){ $posts_to_update = new WP_Query(‘cat=x&showposts=1000’); while($posts_to_update ->have_posts()) : $posts_to_update ->the_post(); $postUpdateArray = array(); $postUpdateArray [‘ID’] = $post->ID;//Don’t remove this. The ID is mandatory $postUpdateArray [‘post_title’] = … Read more

Overview with latest edited posts and pages

You can use the $WPDB query to query the DB, an example would be: $editedposts = $wpdb->get_results( ” SELECT ID, post_title FROM $wpdb->posts WHERE post_modified = between DateAdd(DD,-7,GETDATE() ) and GETDATE() ” ); This lists all posts which have been edited in the last 7 days (not tested), you would do something similar to get … Read more

Network wide post count (WP Multisite)

You don’t seem to call posts_count_func() anywhere, so if your transient expires, it’s not getting reset. function posts_shortcode_count_func( $atts ){ $post_count = get_site_transient( ‘total_posts_cache’ ); if( ! $post_count ) { posts_count_func(); $post_count = get_site_transient( ‘total_posts_cache’ ); } return $post_count; } add_shortcode( ‘posts’, ‘posts_shortcode_count_func’ ); According to the docs for get_transient() (which is the non-network version … Read more

Prevent WordPress from giving each post a number

It is more likely theme is adding numbers rather than WordPress. Find out the css style associated with the numbering and set its display value to none. If you are using a browser based on Google Chrome you can highlight the article numbers, right click and select Inspect. Then, under the Appearance | Customize menu … Read more

Only display posts with comments

I ran into this same problem recently and developed a good solution that maintains paging (which some of the answers here do not) and also allows for only targeting certain comment types and comment approved statuses. function has_comments_join( $join, &$wp_query ) { global $wpdb; if ($comment_term = $wp_query->get(‘post_has_comments’)) { $join .= $wpdb->prepare(” JOIN $wpdb->comments ON … Read more

How to add one time a new page?

If this code is in functions.php or directly in plugin code, the for loop at the top will run every time WordPress is loaded, and the hook at the end refers to a function which doesn’t exist. So probably what you want is to put the top code in a function: function zed93_create_new_page { for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)