New answers tagged

1

You may use a code like this: if ($the_query->have_posts()) { $first_post = $the_query->posts[0]; echo "1st post title\t:"$first_post->post_title; }


0

Solution: sanitize_post is coming with "display" default filter option. And it does not sanitize tags. But if you tries a code like this: $sanitizer = function($post){ return sanitize_post($post, "db"); // or "edit" }; array_map($sanitizer, $data["post"]); Now it sanitizes fields against XSS!


0

I am no expert but you are submitting multiple checkboxes with the same name attribute. Your current form GET action will return the url params like this for example... http://www.urltoshow.com/ville/paris?style=Classique&syle=Luxe So because there are 2 usages of param style in the url above, it means PHP $_GET['style'] will only return the last getted ...


0

It looks like your loop is running through all the posts, your array of post id isn't getting passed. However, you may be able to make the call using this code Get excerpt using get_the_excerpt outside a loop tl;dr $text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id)); https://wordpress.stackexchange.com/a/150005/26744


0

There are 2 methods. The ultra slow method, and the fast method The Ultra Slow Method This method is easy to implement, but can place a massive load on the database, and can cause major performance issues ( as well as severely reduce the number of people who can access your site at the same time ). This is the post__not_in argument. I do not recommend using ...


3

If I understand it correctly.. What you're looking for can be achieved using the CASE statement in MySQL, where you would use the following in the ORDER BY clause: # group the quantity meta into two groups CASE # group one - all quantities that are 1 or more; we flag them as "1" WHEN wp_postmeta.meta_value+0 > 0 THEN 1 # group two - ...


4

Actually, there are many ways to do what you asked, but I'm going to give you an example based on this example on the official React website, which uses AJAX with a class-based component (but there's also an example there using function component with hooks). So for the PHP part, we'll create a custom REST API endpoint and just for testing purposes, we're ...


0

You could possibly look at doing this the same way that WP Job Manager does: https://github.com/Automattic/WP-Job-Manager/blob/master/assets/js/ajax-filters.js This is done by triggering a handler to make the query defining what "page" the query should run against. I would recommend using that as an example to build off of, as it works with both ...


0

Actually, I don't think you need that mt1.post_id IS NOT NULL DESC sorting, hence you also do not need to use the posts_orderby hook. You can just use the orderby parameter in WP_Query like so: Also note that, in the first meta query clause named/keyed start_date_value, you should set the type arg to DATE (like you can see below) so that MySQL/MariaDB casts ...


1

Seems like you have a missing array in tax_query instead of 'tax_query' => array( 'taxonomy' => 'st_tour_type' ), should be 'tax_query' => array( array ( 'taxonomy' => 'st_tour_type', 'operator' => 'EXISTS' ) ), When using tax query without terms/fields we must include the "operator" property. ...


1

You can find the post using get_posts() and the meta query (in my example, I used meta_key and meta_value) like so: See the function reference for more details on the parameters (and other examples that might help you), but the 'fields' => 'ids' means that the function will return only the post IDs and not full post object/data. <?php // Find a "...


1

You mixed meta query and tax query It should look like this $query = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 12, 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'instock' ) ), '...


0

This is not possible, you cannot query sub-values of serialised/structured data in post meta values. To fix this, you need to store the dates you want to query/filter by as separate post meta key/value pairs. Values need to be string/number/boolean whole values to be queried this way. They cannot be complex structures or sub-strings, such as JSON, arrays, ...


1

ORDER BY ID ASC $args = array( 'order' => 'ASC', 'orderby' => 'ID', ); or ORDER BY ID DESC $args = array( 'order' => 'DESC', 'orderby' => 'ID', );


Top 50 recent answers are included