New answers tagged

0

The fix I did was to put in a filter to deal with the 0 = 1 issue: In my case, I was trying to only affect the product post type, so I didn't want to filter and affect all SQL statements. add_filter( 'posts_where', 'acff_sqlfix', 10, 1 ); function acff_sqlfix( $sql ) { if ((get_query_var( 'post_type' ) == 'product') && (strpos($sql, ' 0 = ...


0

If you're set to a static front page, why would there be pagination? The proper way to have a paginated grid of posts as your front page is to set the homepage to "Your latest posts". You would then develop your front-page.php, home.php or index.php template to display posts as a grid (use the Template Hierarchy to determine which file you need). In that ...


1

One option could be to use data attributes on the entires listed on pages one and two. Then attach a click event that reads the attribute value on click saves it to localStorage. This way you wouldn't need to make an extra db call on page three. In the loop the data attribute value can come basically from anywhere. E.g. post meta, some post field, taxonomy ...


0

The code shown isn't working as wished, what is wrong? you're using only the first tag : $first_tag = $tags[0]->term_id; to grab posts from all tags you have to iterate the whole array until a max of 5. The code below ( untested) grabs a max of 25 posts theoretically using up to 5 tags..BUT if you have 25 posts belonging to the first tag you will have ...


0

You might have forgotten wp_reset_postdata() after the while statement as well: apartquery = new WP_Query($apartargs); if ($apartquery->have_posts()) : while ($apartquery->have_posts()) : $apartquery->the_post(); // Your content endwhile; wp_reset_postdata(); else : // Your ...


1

I think the issue is that it's being interpreted as a STRING type and being ordered character by character. Maybe try turning this into a meta query and forcing the DATETIME type like the example shown below: 'meta_query' => array( 'starttime' => array( 'key' => 'start_time', 'type' => 'DATETIME', ) ), 'orderby' => ...


0

Yeah, so: First: you should not use query_posts. No, not even if you need ajax pagination. However, this is not your current problem. To be able to sort the "price on request" Properties to the end of the list regardless of the price-sorting, you simply need to save the "price on request" information in another meta field. The reason you need to do this is ...


0

In the WP Docs you can find the answer. I have not tested this snippet, but it should become something like this: $args = array( 'post_type' => 'product', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'product-ean', 'value' => 123, 'compare' => '=', ...


0

You can find here the solution: https://developer.wordpress.org/themes/basics/template-hierarchy/#category Rendering category archive index pages uses the following path in WordPress: category-{slug}.php – If the category’s slug is news, WordPress will look for category-news.php. category-{id}.php – If the category’s ID is 6, WordPress will look ...


0

I think using the pre_get_posts action should do the trick. Something along these lines. Modify as needed. Add to functions.php. function my_limit_admin_posts($query){ if ( is_admin() && $query->is_main_query() && 'your_post_type' === $query->get('post_type') && current_user_can('some_capability_or_role') ) { $query->...


0

This worked for me. 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'colors', 'compare' => 'NOT EXISTS' // doesn't work ), array( 'key' => 'colors', 'value' => 'blue' ) )


0

You can use meta_query property when fetching post data using new WP_Query() $vehicles = new WP_Query([ 'post_type' => 'vehicle', 'meta_query' => [ 'relation' => 'AND', [ 'key' => 'wheel', 'value' => '4', ], [ 'key' => 'color', 'value' => 'blue',...


0

You can use post__not_in with the get_the_ID of the post in this case your code should be like this : $args = array( 'post_type' => 'custom_post_type', 'tax_query' => array( array( 'taxonomy' => '...


1

Thanks! We ran into the same issue and this question helped a lot! Alternate Use Case We're looping through a custom post type called events (surprise, surprise, it stores events). It stores a timestamp in the meta field ev_start (event start time). We actually were able to just use the orderby value meta_value_num (as you can see meta_type is commented out)...


0

I finally found some helpful information in this post: How to "Load More" posts via AJAX? The issue ended up being a combination of counting the number of total pages of posts, and sharing that number with the hooked ajax function in functions.php. Here's my page template loop: <div class="events"> <?php $socal_cats = array( '...


0

Use a meta query. Since ACF stores dates as Ymd you can just treat the value as a number: $date_query = array( 'key' => 'start_date', // ACF date field name 'type' => 'NUMERIC', 'value' => '20200101', 'compare' => '<=', // All posts with start date before/on January 1st 2020 ); $args['meta_query'] = array( $date_query ); Any ...


0

To everyone experiencing the same issue, I have seem to solved it by doing the following: Get a clean copy of WordPress Replace the WP-Content folder Copy your original/existing themes, plugins and upload folder back into that new wp-content That's it... I know, it makes no sense but it somehow did the job.


0

First, take a look at this: https://developer.wordpress.org/reference/classes/wp_query/ You can filter by querying by post type, or in a single query (code between /* */). <?php //This is the first query $query_A = array( 'post_type' => 'post_type_A', 'post_status' => 'publish', //'cache_results' => true, 'posts_per_page' =&...


0

Try something like that The reverse of this: https://wordpress.stackexchange.com/a/209714/180599 <?php global $wpdb; //The reverse of this: https://wordpress.stackexchange.com/a/209714/180599 $supported_mimes = array( 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/tiff', 'image/x-icon' ); $all_mimes = get_allowed_mime_types(); $...


1

If you have a form you should have a sort field in it, so that you can send your order value on form submit. This way you can send the sorting parameter to your backend callback function. If you don't have a form you shoud add this parameter to another element with a data attribute like that: <button id="load-more" data-order="DESC">Load More</...


0

You should just be able to achieve the same effect using CSS and display:flex - I don't think you need to break your loop up into threes.


2

The problem is that, you have added extra white space before wp_ajax action. remove space from actions ' wp_ajax_my_action' and ' wp_ajax_nopriv_my_action'. because of extra space before ajax request, showing the 400 bad request error. You should use : add_action('wp_ajax_my_action', 'my_action'); add_action('wp_ajax_nopriv_my_action', 'my_action');


Top 50 recent answers are included