Query to list all galleries under a parent post?
I had to set the post type in the query. ‘post_type’ => ‘gallery’ Problem solved!
I had to set the post type in the query. ‘post_type’ => ‘gallery’ Problem solved!
You should be able to use pre_get_posts to change the query. I’d suggest creating a custom plugin, so that if you ever change your theme your modifications will still apply. To get you started, here’s how you can set the post types being searched: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if … Read more
$tenantsInfo = $wpdb->get_results(“SELECT * FROM exp_ten WHERE tenant_number = ” . (int) $user->ID .” ORDER BY DESC”);
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’ );
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>”; } }
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
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
To have the pagination work properly you need to filter the posts at the WordPress main query level using the pre_get_posts action. By looking at your code, I don’t see where the post specific information is involved. Is $course_options holding information for the post?
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
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