Query posts from current year

You just need get current date and add it on data_query in wp_query, Look this: <?php $getdate = getdate(); $args = array( ‘date_query’ => array( array( ‘year’ => $getdate[“year”] ), ), ); $query = new WP_Query( $args ); ?> and then use loop: <?php if ( $query->have_posts() ): while ( $query->have_posts() ) : $query->the_post(); the_title(); … Read more

wp_dropdown_categories with multiple select

wp_dropdown_categories has a filter applied to the output that is called right before the function returns or echos the output. With this you can add a filter to your funtions.php file that manipulates the select field and adds a multiple attribute to it. The filter below would search for the select opening tag and add … Read more

Are there any scenarios where the query_posts may be used?

query_posts() is useful in cases when there is no main query: calls to wp-admin/admin-ajax.php, wp-admin/admin-post.php or wp-login.php for example. Yes, you can achieve the same results there without query_posts() and slightly less compact code instead. But if you don’t have to care about side effects, using query_posts() is acceptable.

Compare two numeric custom fields

I think something like this, but not tested, and my SQL-foo is rather weak: $test = $wpdb->get_col( $wpdb->prepare( ” SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts INNER JOIN $wpdb->postmeta AS mt1 ON ( wp_posts.ID = $wpdb->postmeta.post_id ) WHERE $wpdb->postmeta.meta_key = ‘goals-made’ AND( mt1.meta_key = ‘goals-against’ AND CAST($wpdb->postmeta.meta_value AS INT) > CAST(mt1.meta_value AS INT) ) ” )); This … Read more

Is `query_posts` really slower than secondary query?

You ask: is query_posts really slower than some secondary query… The fact is that if you’re calling query_posts() from a theme then it already is a secondary query. WordPress has already queried the database once to get a certain page then it hits your query_posts() function and queries the database again creating a second query … Read more

Remove [gallery] shortcode altogether

The short code is actually entered into then page or post content so disabling the short code processing prevents the gallery short code from being replaced with the gallery images but it doesn’t affect the post content. The best solution is to add a new short code handler after removing the default gallery handles. Another … Read more

Problem with ‘post__not_in’

You are trying to supply an array as part of the string query parameter. You could instead just supply the arguments list as an array like this: $newQuery = new WP_Query( array( ‘posts_per_page’ => 5, ‘orderby’ => ‘rand’, ‘cat’ => $cats[0]->term_id, ‘post__not_in’ => array($exclude_post) ) );

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