How do I use get_query_var() within plguin code
get_query_var works within any code, theme or plugin. But it will only return meaningful data after the query has been processed. So, use it on the init hook or later.
get_query_var works within any code, theme or plugin. But it will only return meaningful data after the query has been processed. So, use it on the init hook or later.
$current_month = date(‘m’); should be $current_month = date(‘n’); Reference the page for the WP_Query object: codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters “month_num” is an int from “1-12”, not from “01-12”. The way the variables are currently set up, $current_month has a preceding zero. I’m assuming that a simple change to return the month without a preceding zero will fix this. … Read more
When it comes to retrieve posts, it’s supposed to call WP_Query. WP_Query has an argument called meta_query but it doesn’t have comment_query. So it might need a trick to achieve what you want, $args = array(); $args[‘feed’] = 1; $args[‘withcomments’] = 1; $args[‘author’] = 1; //author id. $query = new WP_Query($args); $posts = $query->posts; //do … Read more
Almost all integers in WordPress are treated as strings. If you try to var_dump($post->ID); inside a loop you notice also post id is a string. Normally this is not a problem because of PHP auto type casting feature. This can be a problem, when you do strict comparison, like 1 === $post->ID or in_array(1, $ids, … Read more
build_query() converts an array into a string to be used in an URL. You can pass an array or an object: $test1 = array ( ‘foo’ => ‘bar’, ‘hello’ => ‘world’ ); $query1 = build_query( $test1 ); print “<pre>$query1</pre>”; // foo=bar&hello=world $test2 = array ( ‘foo’ => ‘bar’, ‘hello’ => ‘world’, ‘one’ => array( 1, … Read more
Try this: global $wpdb; $num_cat = 6; $query = “SELECT tt.term_taxonomy_id, t.name, COUNT( t.name ), GROUP_CONCAT( p.ID ) , GROUP_CONCAT(m.meta_value) FROM {$wpdb->prefix}term_taxonomy tt NATURAL JOIN {$wpdb->prefix}terms t NATURAL JOIN {$wpdb->prefix}term_relationships tr JOIN {$wpdb->prefix}posts p ON ( tr.object_id = ID ) JOIN {$wpdb->prefix}postmeta m ON ( post_id = ID ) WHERE taxonomy = ‘category’ AND post_type=”post” … Read more
You made a lot of statements here, so let’s go through them bit by bit. while keeping database queries low The amount of queries isn’t directly an issue, time that they take is. Single really slow query can take more time than hundreds of very fast ones. before the website loads (or the first time … Read more
UPDATE wp_posts SET post_author = [NEW_ID] WHERE post_author = [OLD_ID]
I finally found a workaround for this, here it goes : I used “get_user” with a “has_custom_post_type” function to query every user with at least one article written and then added the link to their blog CPT by adding “/blog/display_name” in the href. Here goes the code <?php $blog_url = get_bloginfo(‘home’); $users_number = 0; $blogusers … Read more
These look like 2 separate questions. The first I think is a single vs double quotes issue: Try this: $html=””; foreach ( $recent_across_network as $post ) { $html .= ‘blog_id, ‘.$post->ID.’ ) . ‘”>’ . $post->post_title . ”; } $html .= ”; The line in the foreach is putting $post->ID in single quotes which won’t … Read more