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

Get posts by category with pure SQL query

If you want to be able to get the category by name, this should work: SELECT DISTINCT substr(post_title, – instr(reverse(post_title), “https://wordpress.stackexchange.com/”) + 1) AS year FROM {$wpdb->posts} p LEFT JOIN {$wpdb->term_relationships} rel ON rel.object_id = p.ID LEFT JOIN {$wpdb->term_taxonomy} tax ON tax.term_taxonomy_id = rel.term_taxonomy_id LEFT JOIN {$wpdb->terms} t ON t.term_id = tax.term_id WHERE post_status=”publish” AND … Read more

Dynamically excluding current page id

In your code, if $post_id were, say, 99, this: query_posts(“showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=”. $post_id .””); would result in this being passed to query posts: query_posts(“showposts=4&post_type=page&post_parent=168&orderby=rand&exclude=”. 99 .””); so, your issue here is ‘. 99 .’ isn’t a valid value for exclude. That said, query_posts should only be used to alter the main loop in a template. if you … Read more

Sorting Posts Via Custom Taxonomy Values Using Checkboxes?

Wrap the whole thing within a form and add a submit button in it: <form method=”POST” action=””> <ul class=”filter-sub-dropdown”> … </form> Use term IDs as checkbox values instead of slugs (you’ll save a little server resources): $discipline->slug; > $discipline->term_id Then, in your functions.php file check if that form has been submitted, and change WP’s query … Read more

Different amount of posts on homepage than paged pages

You should use the pre_get_posts filter. You can exclude the homepage with ! is_front_page or ! is_home depending on your configuration. /** * Changes the number of posts per page if not is_home * * @author SFNdesign, Curtis McHale */ function wptt_change_posts_on_page( $query ) { if ( ! is_home() && $query->is_main_query() ) { $query->set( ‘posts_per_page’, … Read more

Return category slug / title from category ID

get_category will return all the information you need for both cases. $catinfo = get_category(get_field(‘category_test’)); From the Codex, that will give you (sample data obviously): stdClass Object ( [term_id] => 85 [name] => Category Name [slug] => category-name [term_group] => 0 [term_taxonomy_id] => 85 [taxonomy] => category Return category slug / title from category ID => … Read more

How to make an archive page displaying posts in a date range

Saving the date in post meta is a slightly more sane approach, the post_date column was not designed with your use case in mind. You may get weird results with dates before the Unix epoch (January 1, 1970). Then it’s just a simple meta_query to load posts between dates, no filter necessary. $start=”1900-01-01″; $end = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)