How to hide post in WordPress

I think you need in your query is post__not_in but you aren’t showing any code: taken from WP_Query: $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘post__not_in’ => array( 2, 5, 12, 14, 20 ) ) ); if you want to exclude that particular post you’re in you would do: ‘post__not_in’ => array($post->ID), Other questions … Read more

Sort posts in a specific way

This is possible with native query parameters like this: $posts = get_posts([ ‘post__in’ => [2,5,3,1,4,6], ‘orderby => ‘post__in’, ]); This combination will instruct WP to fetch specific posts by ID and order them in the specific way that you supplied IDs.

How to use printf to output two links?

This should do it: $text = __( ‘<strong><a href=”https://wordpress.stackexchange.com/questions/268780/%1$s”>login</a> or <a href=”https://wordpress.stackexchange.com/questions/268780/%2$s”>register</a> to be able to add new adverts</strong>’, ‘adverts’ ); printf( ‘<div>’ . $text . ‘</div>’, wp_login_url(), wp_registration_url());

Make plugin php file called directly aware of WordPress?

You can’t load plugin files directly, you need to target either a front-end or admin URL that bootstraps WordPress. An easy way to do this is the admin_post_(action) action: add_action( ‘admin_post_add_foobar’, ‘prefix_admin_add_foobar’ ); function prefix_admin_add_foobar() { // your code here } You can then POST your data to admin_url( ‘admin-post.php’ ) and set action to … Read more

How can get all users by current user meta?

You can achieve this using get_users function and its meta_key argument as displayed below. $users = get_users(array( ‘meta_key’ => ‘blocking_users’, )); var_dump( $users ); To retrieve it for current user and print it, please use below code. $user_id = get_current_user_id(); $key = ‘blocking_users’; $single = false; $blocking_users = get_user_meta( $user_id, $key, $single ); echo ‘<p>The … Read more

Calculate days between two custom field value dates

We can use something like human_time_diff() to give us a readable time difference. First we need to see if the days are the same: $date1 = get_field( ‘date_start’, false, false ); $date1 = new DateTime( $date1 ); $unix1 = strtotime( $date1->format( ‘Y-m-d’ ) ); $date2 = get_field( ‘date_fin’, false, false ); $date2 = new DateTime( … Read more