Query post category & remove any post id

If you are trying to omit posts 1,3,5 from category 3 on your blog, you can use the following code $query = new WP_Query( array(‘cat’ => 3, ‘post_type’ => ‘post’, ‘post__not_in’ => array(1,3,5) ) ); The query results will not show posts with ids 1,3,5 of category 3.

Custome column sort by date not title

After a lot of guess work and research I’ve managed to come up with a simple solution. function column_orderby( $vars ) { $vars[‘orderby’] = ‘date’; $vars[‘order’] = ‘desc’; return $vars; } add_filter( ‘request’, ‘column_orderby’ ); This will sort all of the columns by ‘date’ as well as order them by ‘desc’! Hope it helps anyone … Read more

Modify WordPress loop after it has been run

First: Indent your code consistently, your code editor should do this automatically, if it doesn’t, you should change, I can recommend Sublime Text as a free option, but there are hundreds of others Don’t spam PHP tags, <?php echo ‘you’; ?><?php echo ‘ dont ‘; ?><?php echo ‘need ‘;?><?php echo ‘this’; ?>, when <?php echo … Read more

Sort / Filter Queries

You can use either GET or POST requests to achieve that functionality without using any AJAX (which, in fact, does the same but uses JS to process requests). You need to add ?name_of_var=value after trailing slash on labels that link to different queries. Basically, your ‘Coca-Cola’ link has to look this way: site.com/products/?brand=cocacola After that, … Read more

Get posts by category or author

I used the following in my child theme ‘functions.php’ to get posts by category name. You can also use category ID number but that didn’t work for me. add_action(‘pre_get_posts’, ‘ad_filter_categories’); function ad_filter_categories($query) { if ($query->is_main_query() && is_home()) { $query->set(‘category_name’,’tips’); } }

No duplicate tags by category

I did something similar in the past project and this is my solution. I hope this is what you want. <ul class=”inline-list”> <?php query_posts(‘category_name=lain-lain’); if (have_posts()) : while (have_posts()) : the_post(); if ( get_the_tag_list() ) : $count = 0; foreach ( get_tags() as $value ) { if ( $count>=10 ) break; $output .= ‘<li><a href=”http://example.com/tag/’.strtolower( … Read more

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