list posts and wrap them alphabetically A-Z

I would do it the other way around- loop over the alphabet and check all posts for a match with each letter. $all_posts = new WP_Query( array( ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1 ) ); if( $all_posts->have_posts() ){ foreach( range( ‘A’, ‘Z’ ) as $letter ) { echo ‘<div class=”group_letter”><div class=”letter”>’ . … Read more

Get taxonomy terms only of the WP_Query current posts

You’d probably do something like this $args = array( ‘post_type’ => ‘product’, ‘product_cat’ => get_queried_object() ); $query = new WP_Query( $args ); $termsInPosts = array(); if ( $query->have_posts() ) { while( $query->have_posts() ) : $query->the_post(); $postTerms = wp_get_post_terms(get_the_ID(), ‘brands’, array(‘fields’ => ‘term_id’)); foreach ($postTerms as $postTerm) if (!in_array($postTerm->term_id, $termsInPosts)) $termsInPosts[] = $postTerm->term_id; endwhile; } $marcas_terms … Read more

Sorting Posts | Alphabetical Order

Have you read this thread? Display all posts starting with given letter? This wouldn’t be simple to do with WP_Query and that’s unfortunate because that would help preserve pagination. // Rules $args = [‘post_type’=>’post’,’orderby’=>’name’]; // The Query $query1 = new WP_Query( $args ); // The Loop while ( $query1->have_posts() ) { $query1->the_post(); echo ‘<li>’ . … Read more

storing wp_head in a variable?

This function doesn’t take any params, so there is no nice way of doing it. But of course you can do this PHP way using output buffering 😉 ob_start(); wp_head(); $var = ob_get_clean();

How can i display post loop in table format?

You need 3 separate loops. One for each row, with each post creating a new column: <div class=”acadp”> <table> <tr> <?php while( $acadp_query->have_posts() ) : $acadp_query->the_post(); ?> <td><?php the_title(); ?></td> <?php endwhile; ?> </tr> <tr> <?php while( $acadp_query->have_posts() ) : $acadp_query->the_post(); ?> <td><?php the_content(); ?></td> <?php endwhile; ?> </tr> <tr> <?php while( $acadp_query->have_posts() ) : … Read more

How to override wp-admin styling

As noted by @Fusion, this has changed beginning with version 5. In order to override admin styles for 5.*, you need a hook in functions.php, something like this: function custom_admin() { $url = get_settings(‘siteurl’); $url = $url . ‘/wp-content/themes/my-theme/wp-admin.css’; echo ‘<link rel=”stylesheet” type=”text/css” href=”‘ . $url . ‘” />’; } add_action(‘admin_head’, ‘custom_admin’) Sources: WordPress Codex … Read more