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

Noindex Posts From Certain Authors In WordPress

From codex: is_author() is a conditional tag which determines whether the query is for an existing author archive page. so it does not work for your scope. Best solution, instead of using the template file header.php is to write a function in functions.php hooking the proper action wp_head: add_action(‘wp_head’,’AS_exclude_author_from_indexing’); function AS_exclude_author_from_indexing(){ $toIndex = array(111,112,113); $user_id … Read more

widget_posts_args not using the number of posts in widget

The problem is that you’re not modifying the existing arguments for the widget, you’re replacing them: add_filter(‘widget_posts_args’, function() { $params[‘post_type’] = array(‘post’, ‘recipe’); return $params; }); The result of that filter will be: $params = [ ‘post_type’ => [ ‘post’, ‘recipe’ ] ]; So any other arguments, including the default number of posts, are removed. … 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

Insert page content into another page with a changed variable

Assuming you want to replace it with some static value (well, you can always change this anyway), some kind of find and replace snippet like this can do the trick: $content = apply_filters( ‘the_content’, $post->post_content); // set the replacement string value $replace = “REPLACEMENT”; // make sure the quotes used are exact $find_start = “<param … Read more

Extending WP_Customize_Media_Control to return filename

I have noticed that WP_Customize_Image_Control does indeed return the filename instead of the ID, but this is only for images. That’s because the class extends WP_Customize_Upload_Control which has the type set to upload: class WP_Customize_Upload_Control extends WP_Customize_Media_Control { public $type=”upload”; public $mime_type=””; … } And for Customizer controllers using the above class, the JavaScript controller … Read more

Redeclare function after plugin activation

Ok with helps it’s working. So theme was ok in front of wordpress but wasn’t able to load in the admin so we changed the previous condition by : if (!function_exists(‘get_field’) && !is_admin()) { function get_field() { return; } function the_field() { return; } } but same problem with activation in the admin and it … Read more