Show only oldest post by author

To restrict users to just one post, don’t let them create new posts. Just add one wp_editor() instance to their profile. Hook into ‘show_user_profile’ and ‘edit_user_profile’ to show the editor. Hook into ‘personal_options_update’ and ‘edit_user_profile_update’ to save the content to a user meta or a hidden custom post type. Now they don’t have to search … Read more

How to create a WP_Query to search the Title or Tag?

Please use below code to show posts in texonomy and titles $s = $request[‘s’]; $tags = str_replace(‘ ‘, ‘-‘, strtolower($request[‘s’])); $q1 = get_posts(array( ‘fields’ => ‘id’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘s’ => $s )); $q2 = get_posts(array( ‘fields’ => ‘ids’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tag’ … Read more

Fulltext search in posts sorted by relevancy

You may want to check the Sphinx search engine http://sphinxsearch.com/ It took me about one day to set it up and learn how to use, but it does really good job with sorting by relevancy and grammar stemming. Also it is faster than fulltext search for big data sets thanks to indexing.

Query & Sort Comments by custom comment meta

Unfortunately it’s unsupported by the applicable WordPress functions for querying comments, which is primarily due to(i feel) not enough people(or anyone) yet asking for it. I want to highlight a couple of core files here to help understand the issue. First up comments-template.php, the comment_template function, it’s this function that queries for comments and then … Read more

How to find objects by terms

Assuming “users” you are trying to pull is a custom post type. You can use “tax_query” as below. $user_args = array( ‘post_type’ => ‘custom_user_post’, // Custom post type, ‘posts_per_page’ => 10, ‘paged’ => ( ! empty( get_query_var( ‘paged’ ) )? get_query_var(‘paged’): 1 ), ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘user_sports’, //assuming your … Read more

Search Terms – Querying on either description__like OR name__like in the same Term Query?

I don’t see any options for WordPress to search terms by both of name & description. So i combined 2 queries like @StephanieQ but maybe more simple way, checkout my ajax response below: public function ajax_project_terms_search() { $results = array(); $search_query = sanitize_text_field($_GET[‘q’]); $withname = intval($_GET[‘withname’]); $search_keys = array(‘name__like’, ‘description__like’); $exclude = array(); foreach ($search_keys … Read more

query multiple taxonomy and show post count

I’m sure that a custom sql query would work much better but here is an option using the WordPress Tools available //first get all categories $categories = get_terms( ‘category’, array( ‘orderby’ => ‘count’, )); //then create an array for easier processing foreach ( $categories as $cat ) { $slugs[] = $cat->slug; $counts[$cat->slug][‘count’] = $cat->count; } … Read more

Very slow query

To check if the query itself is slow or anything else slows it down, try running your query directly in the database, and have a look at how long it takes there. <?php echo $GLOBALS[‘wp_query’]->request; ?> This shows you the latest Query that WordPress ran in your database. If the query is really slow in … Read more

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