Multiple endpoints in one URL

Not sure of the context for this, is it a custom post type or just a page? This might be something which you’re looking for – function add_lead_management_endpoints() { add_rewrite_rule( ‘manage-lead/lead_id/([0-9]{1,})/product_id/([0-9]{1,})’, ‘index.php?pagename=manage-lead&lead_id=$matches[1]&product_id=$matches[2]’, ‘top’ ); add_rewrite_tag( ‘%lead_id%’, ‘([^&]+)’ ); add_rewrite_tag( ‘%product_id%’, ‘([^&]+)’ ); } add_action( ‘init’, ‘add_lead_management_endpoints’ ); You’ll need to flush permalinks for this to … Read more

Get posts with condition on comment meta value

You can first try the following comment query: $comments = get_comments( [ ‘post_type’ => ‘projects’, ‘post_status’ => ‘publish’, ‘type’ => ‘message’, ‘date_query’ => [ [ ‘before’ => ‘5 days ago midnight’, ‘inclusive’ => true, ] ], ‘meta_query’ => [ [ ‘key’ => ‘foo’, // <– Adjust to your needs! ‘value’ => ‘bar’ // <– Adjust … Read more

WP_Query meta_query where meta value ends in space

Note sure how your structure is, but here’s one way, using RLIKE comparison and a space character class: array( ‘key’ => ‘_address_postcode’, ‘value’ => ‘^SC1[[:space:]]’, // Starts with ‘SC1 ‘ ‘compare’ => ‘RLIKE’ ) Maybe you should consider adjusting the meta values, as suggested by @cybmeta? But note that meta queries can be slow, so … Read more

Group posts by custom field

You’re close. You have: foreach (get_child_pages(wp_get_post_parent_id(get_the_ID())) as $s) { echo ‘<li><a href=”‘ . get_the_permalink($s->ID) . ‘”>’ . get_the_title($s->ID) . ‘</a></li>’; } We need to add a layer above that to show the two lists. However we can’t assume that the posts of one type will all come out together (i.e. all of one category, then … Read more

Counting number of posts with Category B in Category A

Make use of the WP_Query class, namely the tax_query and fields parameters. Get the count from the $found_posts property. Please note, this is exemplary code. $query = new WP_Query( [ ‘post_type’ => ‘games’, ‘tax_query’ = [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘game_status’, ‘field’ => ‘slug’, ‘terms’ => [ ‘beaten’ ], ], [ ‘taxonomy’ => … Read more

Duplicate Queries

Generally speaking, you could use the WP Transients API to save the query. // Get any existing copy of our transient data if ( false === ( $special_query_results = get_transient( ‘special_query_results’ ) ) ) { // It wasn’t there, so regenerate the data and save the transient $special_query_results = new WP_Query( ‘cat=5&order=random&tag=tech&post_meta_key=thumbnail’ ); set_transient( ‘special_query_results’, … Read more

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