New answers tagged

0

You can do this several different ways. Need to know how you are passing the 1 custom field in your current shortcode. It seems like you might be doing it like this: [your_short_code price="how_are_you_setting_this"] if this is the case then you can just add more attributes like this: [your_short_code price="how_are_you_setting_this" next_field="...


0

I found that I had a duplicate gallery modal inside a get_template_part funciton that was throwing off the ID. It's now resolved.


1

I believe you need to use get_template_part, but you need to request the get_page_template_slug first. So that would look like: get_template_part( get_page_template_slug( get_the_ID() ) ); in lieu of echo get_page_template(); And no need to echo it, it returns the template already printed.


0

Make sure that you're doing enough with the relations if using AND are you sure that those values exist in the record, try playing with OR.


0

(Revised answer) If I understand it properly, try these: Define $the_post for each "property": <?php $the_post = get_post(); ?> <div class="property-details"> <h2><?php the_title(); ?></h2> ... </div> Then change the drop-down code to: <select name="propname"> <?php $found = wp_list_filter(...


1

You can use the WP_Query::get method to get whatever is in the meta query like this: add_action('pre_get_posts','add_another_meta_query'); function add_another_meta_query($query){ //Be sure to only use the main query on frontend if($query->is_main_query() && !is_admin()){ $meta_query = $query->get('meta_query',array()); $...


0

The solution is to do two queries and then a third query, to set up the wp_query: $query1 = new WP_Query(array ( 'post_status' => 'publish', 'posts_per_page' => $postnumber, 'ignore_sticky_posts' => 1, 'cat' => $category ) ); $query2 = new WP_Query(array( 'post_type' => 'page', 'post__in' => array(1443,1480))); $...


0

You can do it like so: global $post; $posts = get_posts( array( 'post_type' => 'press', 'nopaging' => true, 'orderby' => 'date', 'order' => 'DESC', // it's DESC; not DSC // There's no use setting posts_per_page when nopaging is enabled. // Because posts_per_page will be ignored when nopaging is enabled. ) ); $...


0

Okay, so the answer to this I think is to create a new array that combines your post IDs and the specific IDs you're trying to include, probably in the same way you've done there. Then in your query args, you, you use 'post__in'=> $ids,. Just as an example, here we had some posts selected via ACF, then ran them through our WP_Query. $ids = get_field(...


0

To display post id 149443, inside the first while() loop just use if ( get_the_ID() == 149433 ) and for the others use if ( get_the_ID() != 149433 ). The trick is to rewind the loop between the 2 uses so that you can use it again, so after the first loop use $special_reports->rewind_posts();


2

Does tax_query beats meta_query even in situations like this? No. Taxonomies are appropriate if you have a common set of values that are shared by many posts, and you're doing a simple comparison based on whether the post has or does not have a particular value. They are not appropriate if you need to perform numerical or range comparisons, like your ...


0

Well, I wouldn't say that "tax_query beats meta_query"... They're a little bit different things. When you perform tax_query, then two JOINS are needed in your SQL query. Meta_query results in only one join (if you search for only one meta). So when is the tax_query better? For example when you search for posts assigned to multiple taxonomies. Let's say ...


1

Taxonomy Parameters Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy arrays. In 'tax_query' you should add array of ...


0

use this snippet here i get image which have post id 5 <img src='<?php echo site_url(); ?>/wp-content/uploads/<?php echo get_post_meta(5,'_wp_attached_file',true); ?>' height="100" width="100"> check get_ani_taxonomy_fields($ani->term_id, 'acf_image_field_name') this function return post id


0

Try use get_query_var instead of $_GET and also increase priority function my_pre_get_posts( $wp_query ) { // do not modify queries in the admin if( is_admin() ) { return $wp_query; } // allow the url to alter the query if( isset(get_query_var( 'budget' )) ) { $wp_query->set('meta_key', 'budget'); $wp_query->set('meta_value', ...


0

Change $wpb_all_query->prev_post() to $wpb_all_query->the_post(). Class WP_Query does not have prev_post() method, it has the next_post() method, which takes the next post from the results (set up post member of WP_Query object), but it does not set the global variable. To reach for the data of the current post, you must use $wpb_all_query->post (...


0

The most reliable way to get the current post being viewed is not the global $post variable. Instead you should first check is_singular(), and then use get_queried_object() to get the post object, or get_queried_object_id() to just get the ID. if ( ! is_singular() ) { return; } $post_id = get_queried_object_id(); $args = array( 'post_type' =&...


1

Whenever you use capability_type you need to then assign those capabilities to the roles which should have access to the post type; Otherwise they will not have access to the post type. Awhile back Justin Tadlock wrote an article around capbility_type: Meta Capabilities For Custom Post Types. If you don't want to have to assign these capabilities to roles ...


0

I'm not sure if it's possible to do this in a single query in Wordpress. You could potentially split it into two like below: <ul> <?php global $post; // Get posts by selected post ids $args = array( 'posts_per_page' => -1, 'post__in' => [12345,12543], 'orderby' => 'post__in' ); $myposts = get_posts($args); foreach ...


2

I realize now that you're not talking about WP_Query but WP_User_Query. Looking at the documentation for WP_User_Query it says this about the who parameter: who (string) - Which users to query. Currently only 'authors' is supported. Default is all users. Instead you can use the role parameter and exclude certain users by ID like so: // Grab all ...


1

exclude specific authors from WP_Query You can do it like so: $args = array( 'author__not_in' => array( 10, 3, 4 ), ); $posts_query = new WP_Query( $args ); But if you meant "from WP_User_Query", then in WP_User_Query, you should use the exclude parameter, and that array('who' => 'authors') shouldn't be in meta_query: $args = array( '...


0

$args = [ 's' => $keyword, 'post_type' => ['page'], 'paged' => $paged, 'posts_per_page' => PAGE_LIMIT, 'tax_query' => [ [ 'taxonomy' => TAX_RESOURCE_PAGE, 'field' => 'slug', 'terms' ...


0

I solved the my issue. this code may help others in future. // Display a custom checkout field add_action( 'woocommerce_checkout_before_terms_and_conditions', 'custom_checkbox_checkout_field' ); function custom_checkbox_checkout_field() { $value = WC()->session->get('add_a_product'); ...


0

The advanced solution is a Walker. But simplest sotution is a recursive function, which will work just like Walker. You can use one below: function wpse343409_get_recursive_posts( $type = 'page', $parent_id = 0 ) { // default parent 0 means only top level posts $posts = new WP_Query( array( 'post_type' => $type, 'posts_per_page' =>...


0

Got it working!! :) Final Code: function wpse156319_posts_where( $where, $query ) { global $wpdb; $currentID = $_POST['post_id']; //shows 2069 $post = get_post($currentID); //shows 2068 $parentID = $post->post_parent; $chargs = array('post_parent' => $post->ID, 'post_type' => 'projects' ); $children = get_children($...


Top 50 recent answers are included