WP Meta Query at depth 2
WP Meta Query at depth 2
WP Meta Query at depth 2
You have two options; either bake into the theme (functions.php) or write a simple plugin that auto-creates the post based on hooking into after new site (blog) creation: https://codex.wordpress.org/Plugin_API/Action_Reference/wpmu_new_blog Use the insert post function to do the creation: https://developer.wordpress.org/reference/functions/wp_insert_post/ Then, set as the home page based on ID returned: update_option( ‘page_on_front’, $new_page->ID );
As said in comments, you should use meta_query. For help on how to query posts by ACF meta field, you can check the ACF documentation: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘event’, ‘meta_key’ => ‘location’, ‘meta_value’ => ‘Melbourne’ ); // query $the_query = new WP_Query( $args );
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters <ul> <?php $item=0; $attr = array( ‘post_type’ => ‘lyrics’, ‘date_query’ => array( array( ‘after’ => ‘1 month ago’ ) ), ‘post_status’=> ‘publish’, ‘meta_key’ => ‘youtube_views’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 10 ); $loop = new WP_Query( $attr ); while ( $loop->have_posts() ) : $loop->the_post(); $song_name = get_the_title(); /*YOUTUBE QUERY HERE*/ // … Read more
Let’s say you have 5 instances: 200, 201, 202, 203, 204 NOT IN {200, 201, 202} is equal to IN {203, 204} (all the other instances). So you don’t need your IN operator anymore because its results are already included from using the NOT IN operator. In your case, this logic works assuming an article … Read more
Turns out that it is possible to run a WP_Query inside a pre_get_posts action keeping in mind two simple principles: pre_get_posts action will alter every query that you make, so you need to contain its action specifying which queries you need to alter. In this case, this containment is done with this line: if ( … Read more
You will have to use 2 queries, where in the first loop you should use: $args = array( “post_type” => “post”, “post_status” => “publish”, “orderby” => “date”, “order” => “DESC”, “posts_per_page” => 20, ‘post__in’ => cat, ); (The Query) And in the second: $args = array( “post_type” => “post”, “post_status” => “publish”, “orderby” => “date”, … Read more
As milo stated, I need to use the post_class function to use the post_class filter. By adding <?php post_class(); ?> to the div in my loop I was then able to successfully modify the post class. Below is my full code containing the post_class filter and the post_class function. Reference: https://codex.wordpress.org/Function_Reference/post_class <?php //Call in the … Read more
You do not need wp_reset_query() here use wp_reset_postdata() instead cause it’s a secondary query and you do not need to reset to the original main query. Never use echo in shortcode, replace line : echo “Nothing to show”; with : $html_out = “Nothing to show”; To get what you want you may use : global … Read more
Essentially you are asking how to pass parameters to a shortcode. This can be done with the function shortcode_atts, which has two required parameters: an array of valid parameters and their defaults, and the attributes of the shortcode that is being passed. You would use it like this: add_shortcode( ‘wpse232385_show_news’, ‘wpse232385_news_query’ ); function wpse232385_news_query ($atts) … Read more