Multiple get_posts() queries on one page
slug is not a valid query paramter, so get_posts() will just return X latest posts! Use name instead. http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
slug is not a valid query paramter, so get_posts() will just return X latest posts! Use name instead. http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
If you’re altering the main query, always use pre_get_posts to alter query parameters before the query is run and before the template is loaded. This will be the most efficient and will not break pagination. As of v4, orderby accepts an array of arguments, which gives you the ability to have different order for each … Read more
You shouldn’t really need to “exclude” anything. Just make use of the built in loop tracking. WP_Query will “remember” where you left off. For example: if (have_posts()) { while (have_posts()) { the_post(); echo ‘firstpost##’; the_content(); echo ‘##endfirstpost’; break; } } // do some other stuff if (have_posts()) { while (have_posts()) { the_post(); echo ‘otherposts##’; the_content(); … Read more
You simply need the is_sticky() conditional check and then act on that. You would probably still need the is_home() and !is_paged() conditional check to only target stikies on the first page of the home page if ( have_posts() ) : while ( have_posts() ) : the_post(); if ( is_sticky() && is_home() && !is_paged() ) { … Read more
get_the_content and the_author have to be in a loop so you would need to use other functions to get the content you need global $wp_query; $post = $wp_query->post; $page_id = $post->ID; // page ID $page_object = get_page( $page_id ); // page stuff $author_id = $post->post_author; // author ID $page_content = $page_object->post_content; $author_name = get_the_author_meta( ‘display_name’, … Read more
The first use of wp_reset_postdata() is not redundant its unnecessary. Per the codex Use this function to restore the global $post variable of the main query loop after a secondary query loop using new WP_Query. It restores the $post variable to the current post in the main query. So only use it after your secondary … Read more
If $my_share echoes as “5171,5167,5165” then it is a string not an array… In other words array($string) does not equal array(integer,integer,integer) even if $string equals “integer,integer,integer” because array treats $string as a single value with further values separated by commas. You could use post__in => explode(“,”, $my_share), to convert the string into an array while … Read more
There are two steps to get this working: Add a counter to your main loop, so you can check how many posts are output. If your counter is less than 3, run a second query and output. So for step 1, set a counter before your loop and increment it each time the loop runs, … Read more
You should use $product->get_price() take a look at WooCommerce WC_Product class.
To get the number of posts you can do it easily without a second query with $adsQuery->post_count; But if there’s some reason (I’d love to know the context!) I can’t grasp that the same query has to be run twice and to the database directly- to answer your question as to why it’s not working: … Read more