I am new with php and word press. I have a question that I am using a sql query in my posts to get data from my data base. Now the problem is that I have huge data on my post and I do not have idea how to apply pagination on the data which has been fetched using the SQL query. Here is the code which I am using in my post. … [Read more...] about pagination on data fetched using SQL query
Loop in sql query
SELECT p2.post_title, p2.post_name, p2.guid FROM wp_site.wp_posts p1 INNER JOIN wp_site.wp_term_relationships AS TR ON TR.object_id = p1.ID INNER JOIN wp_site.wp_postmeta AS PM ON pm.post_id = p1.ID INNER JOIN wp_site.wp_posts AS p2 ON p2.ID = PM.meta_value WHERE p1.post_type = 'nav_menu_item' AND TR.term_taxonomy_id = ( SELECT wp_site.wp_terms.term_id FROM wp_site.wp_terms WHERE wp_terms.slug = 'my-menu') AND wp_site.pm.meta_key = '_menu_item_object_id' ORDER BY p1.menu_order ASC; But there is not url in this solution. I thought to use 'post_name' for url, but this 'post_name' isn't the same url, that I get from 'wp_get_nav_menu_items...' method. Could you help me, please? Thanks. … [Read more...] about Get menu items in MySql WordPress database via sql query
I have come across a function before that displayed the exact SQL code that was used. In a loop for example, but can't remember. … [Read more...] about How to display SQL query that ran in query?
Chapter: 1 Paragraph 1 - Tags (happy, joyful) Paragraph 4 - Tags (sad) Paragraph 8 - Tags (hungry) Chapter: 2 Paragraph 2 - Tags (happy, joyful) Paragraph 3 - Tags (sad) Paragraph 5 - Tags (hungry) Query - Tags = 'sad' Returns Chapter 1, Chapter 2, Paragraph 4, Paragraph 5 I have tested a very inefficient solution where I loop through each post, loop through each relation checking for the right tag. Then storing that post aside including the parent, making sure to not store duplicates. It returns things correctly, but adhorently slow. … [Read more...] about Query nested posts, return if top level post contains a child certain tags
$args = array ( 'post_status' => 'draft', 'posts_per_page' => 10, 'category_name' => $language_sql_param, //fixed 'meta_query' => array( array( 'key' => 'review_rating', 'value' => '3', 'compare' => '>', 'type' => 'NUMERIC', ), ), 'cache_results' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'suppress_filters' => true, 'meta_key' => 'review_id', 'orderby' => 'meta_value_num', ); $wp_query = new WP_Query( $args ); I am filtering posts based on a category(s) they belong too, in my case they are country codes. Here's the SQL that WP generates when I set $language_sql_param to this: … [Read more...] about SQL returned by Wp_Query has wp_posts.ID = -1