get_the_ID() doesnt work

get_the_ID is a WordPress core fuction in the global namespace, so you can’t make a second function called get_the_ID as it won’t know which one to use. You should just call get_the_ID() without writing a new function. For your example code, you could do something like this: <div> <?php echo do_shortcode( ‘[svg-flag flag=”‘ . get_post_meta( … Read more

How to sort a WP_Query by a custom field AND ALSO filter by a different custom field

to sort the posts by a meta field you need to have this field in meta_query and in orderby like this $query_args = array( ‘post_type’ => ‘MY_POSTTYPE_NAME’, ‘post_per_page’ => -1, ‘meta_query’ => array( ‘show_post_query’ => array( ‘key’ => ‘SHOW_POST’, ‘value’ => ‘1’ ), ‘MY_FIELD_NAME__order_by’ => array( ‘key’ => ‘MY_FIELD_NAME’, ‘type’ => ‘NUMERIC’, ‘compare’ => ‘NUMERIC’, … Read more

Convert a string into a decimal number for use in query

For decimal values, use DECIMAL as it says in the official WP_Query documentation: ‘meta_value‘ – Note that a ‘meta_key=keyname‘ must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, … Read more

Show message when query has no posts

Answer I found the answer, thanks to a comment and after some digging myself: function dfib_jobs_shortcode( $atts ) { ob_start(); $query = new WP_Query( array( ‘post_type’ => ‘jobpost’, ‘posts_per_page’ => -1, ‘order’ => ‘ASC’, ‘orderby’ => ‘rand’, ) ); ?> <div class=”vacatures__wrapper”> <?php if ( $query->have_posts() ) { ?> <?php while ( $query->have_posts() ) : … Read more

WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank

If you haven’t done so already, I would recommend you to turn on debug logging in wp-config.php as it makes it easier to trace the error in your code. // added to wp-config.php define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_LOG’, true ); // find error.log in /wp-content, shows backtrace for errors define( ‘WP_DEBUG_DISPLAY’, false ); // … Read more