Combine “Exclude” Query in functions.php

Just put both if statements with || (or) in the one callback function: function wpse_283481_exclude_posts( $query ) { if ( ( $query->is_main_query() && $query->is_home() ) || $query->is_feed() ) { $query->set( ‘cat’, ‘-103’ ); } } add_action( ‘pre_get_posts’, ‘wpse_283481_exclude_posts’ );

mysql query – how to escape apostrophe?

Use esc_html() when outputting a string value inside tags. Use esc_attr() when you’re outputting a string value inside an attribute=””. If you’re outputting a URL, use esc_url() instead of those two. if ($tenantsInfo) { foreach ($tenantsInfo as $tenant) { echo “<h2>Welcome, ” . esc_html( $tenant->tenant_name ) . “</h2>”; } }

Get specific ACF key and value from all posts – no access to DB

Why are you using $wpdb? This is a simple query, check the ACF docs for usage examples (https://www.advancedcustomfields.com/resources/query-posts-custom-fields/) <?php // args $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘product’ ); // query $the_query = new WP_Query($args); ?> <?php if( $the_query->have_posts() ):?> <ul> <?php while( $the_query->have_posts() ) : $the_query->the_post();?> <li> <?php the_title();?> – <a href=”https://wordpress.stackexchange.com/questions/285872/<?php … Read more

Valid SQL query return empty

There are view issues with the query: First what the @janh wrote. Second why you removing the am/pm when you could easily use the date(“Y-m-d H:i:s”); Third, there is this little helper for the database table prefixes $wpdb->prefix Users table the column name is display_name Also when you make aliases is a good rule to … Read more

Custom Post Type setup

You can set any arbitrary path in the rewrite slug and has_archive arguments: $args = array( ‘rewrite’ => array(‘slug’ => ‘people/researchers’), ‘has_archive’ => ‘people/researchers’, // other args… ); EDIT Your post type slug is researchers, so WordPress will be looking for the file archive-researchers.php by default. If you want to force a different template, you … Read more

Query for specific custom field

Data associated to a user can be saved in user meta. Save the recipe post IDs in an array for the user. $my_favs = array( 42, 23, 99 ); update_user_meta( get_current_user_id(), ‘user_favs’, $my_favs ); Then to query all recipe posts with those IDs, pass the array as the post__in argument to WP_Query: $my_favs = get_user_meta( … Read more