Query Custom Post by Category

Are these custom taxonomies or the regular categories? if they are just categories you should use: $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘news’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘category_name’ => ‘Alumni’ ); $loop = new WP_Query( $args ); <?php while ( $loop->have_posts() ) : $loop->the_post();?> … <?php endwhile; ?> if you want … Read more

How to show only one post for each categories of taxonomy of custom post that contains a specific custom field

<?php // get all terms of the `bank` taxonomy $banks = get_terms( array( ‘taxonomy’ => ‘bank’, // more arguments can be used, see (1) below the code ) ); // look through banks, picking one post from each foreach ( $banks as $bank ) { $args = array( ‘post_type’ => ‘account’, // your custom post … Read more

Query to get the author who having maximum number of post (custom post type)

You can try with the following query, where the author data as well as the post count can be retrieved. $sql = “SELECT SQL_CALC_FOUND_ROWS wp_users.ID,post_count FROM wp_users RIGHT JOIN (SELECT post_author, COUNT(*) as post_count FROM wp_posts WHERE ( ( post_type=”custom-post-type” AND ( post_status=”publish” ) ) ) GROUP BY post_author) p ON (wp_users.ID = p.post_author) WHERE … Read more

Is it possible to filter the wp_footer() scripts, read the content, and insert them inline?

For scripts you can use the script_loader_tag filter, which is run right before the script tag is output. It filters the HTML <script> tag, but it also passes the handle and URL that you can use to extract the contents and replace the script tag with a version that has the script inline: function wpse_292955_inline_script( … Read more

Finding post content that begins with a specific character

Something like this will probably work: $results = array(); $allPosts = get_posts(‘post_type=post&numberposts=-1’); foreach ($allPosts as $aPost) { if ( substr($aPost->post_content, 0, 1) == ‘<‘ || substr($aPost->post_content, 0, 2) == ‘<a’ ) $results[] = $aPost->ID; } echo “<pre>”.print_r($results,true).”</pre>”; UPDATE: but you should revisit the MySQL approach in the links you provided. This php method is somewhat … Read more

WP_Query use for a filter with multiple Taxonomies and Terms

Try this way: $args = array( ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); if ( isset( $_POST[‘typefilter’] ) && $_POST[‘typefilter’] !== ” ) { $args[‘post_type’] = ‘post_type_x’; $args[‘tax_query’][0][‘taxonomy’] = ‘type_emp’; $args[‘tax_query’][0][‘field’] = ‘id’; $args[‘tax_query’][0][‘terms’] = $_POST[‘typefilter’]; $args[‘tax_query’][0][‘operator’] = ‘IN’; } if ( $_POST[‘typefilter’] == ”) { $args[‘post_type’] = ‘post_type_x’; } // If … Read more

WP_Query with custom post_type and cat retrieving unwanted posts with the custom posts

Assuming that you have a CPT with slug projets and you’ve registered built-in categories for that CPT, it all looks correct. So there are two possibilities, that I would check: Typos – maybe you misstyped your CPT name somewhere in your code. pre_get_posts filter is modifying your query and changing its behavior (it’s pretty common … Read more