New answers tagged

0

Use get_categories first to get all the post categories to use in the form, then loop through them to display a multicheck input... function hierarchical_category_inputs ($cat, $indent) { $cats = get_categories('hide_empty=false&orderby=name&order=ASC&parent='.$cat); $indent++; if ($cats) { foreach ($cats as $cat) { ...


1

Use this: $query = new WP_Query( array( 'cat' => 4 ) ); Where 4 is the ID of the top-level category (Blackburn). This query will in clude subcats. Reference - WP_Query


0

The best practice is the following: Put your Javascript code in a file, yourcustomjs.js, and store it in your theme folder. I would recommend yourtheme/js/yourcustomjs.js. Be sure that you wrap your script, where needed, in a Document.ready function like the following: jQuery(document).ready(function($) { // your code }); This enables you to ensure ...


0

You can try get_pages like this way: <?php $args = array( 'child_of' => 'YOUR PAGE', 'parent' => 'YOUR PAGE', 'post_type' => 'attachment', 'post_status' => 'publish', 'numberposts' => -1 ); ?> NOTE: child_of Note that the child_of parameter will also fetch "grandchildren" of the given ...


0

To find projects happening within a range of dates, there are 3 cases you have to account for: A project starts within the range A project ends within the range A project starts before the range and ends after the range You can test for these 3 cases separately with an OR meta query and 1 nested AND: 'meta_query' => array( 'relation' => 'OR', ...


0

First, do not use query_posts! (Why not? That is why!) Second, if your custom fields (CF) are saved in the Ymd-form (you are sure about that, yes?!), everything should be fine, even if you do not define the "type" as "date". Reading through several discussions on SE, etc. it seems to be better just to avoid the "date"-type, if you are not comparing a ...


-1

The answer it seems was using 'RAND' instead of 'rand'.


0

You can check: wp_category_checklist You can define a custom walker and change the check-boxes to drop-down with multiple select. wp_category_checklist output an unordered list of checkbox <input> elements labeled with category names.


1

There are few issue with your code When using WP_Query in conjuction with the_post() or using get_posts() in conjuction with setup_postdata( $post ), you need to reset the $post global with wp_reset_postdata(), not wp_reset_query(). wp_reset_query() is used in conjuction with query_posts() which you should never ever use You would want to reset posdata ...


1

Just found the answer.. Add posts_per_page in the arguments as -1. It should look like this: $args = array( 'post_type' => 'lirik_melayu', 'posts_per_page'=> -1, // set the limit post to UNLIMITED (-1 is unlimited) 'orderby' => array( 'ID' => 'DESC' , ), ); $query = new WP_Query( $args ); ...


3

Your syntax is complete wrong in your meta_query. A key/value pair in an array should be in the format of 'key' => 'value'. Your format is 'key', 'value' which in context of an array translate to 0 => 'key', 1 => 'value'. That is why your meta_query does not work. Your failure is also due to not very good housekeeping. As your meta_query is ...


1

Pass the array of arguments with key include. $tags = get_tags(array('include' => '10, 11, 34, 35'));


1

Note that if you have the post slug, you don't need the additional taxonomy query to find that post, so it makes sense to drop the expensive taxonomy query in core in that case. Otherwise you could try instead the post_name__in parameter: [ 'post_name__in' => [ '<postslug>' ], 'tax_query' => [ [ 'taxonomy' ...


0

A quick and easy way would be to just run a search on your Wordpress site on the name of the image. E.g. your-image.png. This should return a list of all the posts which have that image in it.


2

This should be possible with the tax_query parameters for WP_Query. The query is either for posts where any term NOT EXISTS, OR, for any posts where the term IDs are IN the provided array. 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'group', 'operator' => 'NOT EXISTS', ), array( ...


2

Fixed query select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = '_product_id' and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta ...


2

Wordpress comes preloaded with the scripts to do datepickers. If you dont want to do it with a plugin, create a regular text metabox, then you need to enqueue a custom script in the wordpress admin with jquery-ui and jquery-ui-datepicker dependencies: function enqueue_date_picker(){ wp_enqueue_script( 'field-date', ...


0

So here is a quick solution - with a bit of searching over SO and query analyzing : Keep the main query, but add a special filter for ordering. The filter (in function.php) : function my_posts_orderby( $orderby ) { $orderby = 'DATE(wp_posts.post_date) DESC, wp_postmeta.meta_value DESC'; return $orderby; } Note the DATE() mysql function that takes the ...


1

I tried to google "wordpress sql to get post url" and I was pretty astonished I couldn't find any resource sharing the SQL code to join the wp_post table with the table containing the permalink. That is because there is no table containing the permalink. Your "challenge" and your "astonishment" are because you've imagined the system to work in a ...


0

There's no need for multiple queries - posts are, by default, ordered by most recent. Just apply a classname for the first post on the first page: <article <?php post_class( $wp_query->current_post === 0 && ! is_paged() ? 'my-awesome-first-post' : '' ) ?> The first post of the first page will have the class my-awesome-first-post. ...


0

You can try below query SELECT ( SELECT count(*) FROM wp_users as temp WHERE DATE(temp.user_registered) = DATE(wp_users.user_registered) ) as counter, wp_users.* FROM wp_users



Top 50 recent answers are included