SQL Query Search page

you can use WP_Query(); to query the results. it has an argument ‘s’ => $search_query, create an input, get the input value, store it in $search_query, then create a query, $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘s’ => $search_query ) ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // … Read more

SQL trigger failes with post_content

I’ve written a filter for you. It will filter the character before the post get saved in the database and it’s using the WordPress way. If you use this I think you’re not gonna be needed the trigger. Here it is- add_filter( ‘wp_insert_post_data’ , ‘the_dramatist_filter_content_before_insert’ , ’99’, 2 ); function the_dramatist_filter_content_before_insert( $data , $postarr ) … Read more

Select latest 2 articles, but only from given category

Try the below code- SELECT p.*, t.term_id FROM wp_posts p LEFT JOIN wp_term_relationships rel ON rel.object_id = p.ID LEFT JOIN wp_term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id LEFT JOIN wp_terms t ON t.term_id = tax.term_id WHERE tax.taxonomy = ‘category’ AND post_type = “post” AND post_status = “publish” AND t.term_id != 56 ORDER BY ID DESC LIMIT … Read more

Ajax not updating to database

To test your AJAX is working add_action( ‘wp_ajax_editCommittee’, ‘test_ajax_request’ ); add_action( ‘wp_ajax_nopriv_editCommittee’, ‘test_ajax_request’ ); function test_ajax_request() { echo “Request: ” . PHP_EOL; var_dump( $_REQUEST ); exit; } And update your request to move the action into the data sent: jQuery (document).ready (function($) { $ (“.edit_tr”).click (function() { var commitID = $ (this).attr (‘id’); // on … Read more

WordPress Database Posts Table query

Turns out this works. global $wpdb; $postsTable = $wpdb->posts; $results = $wpdb->get_results( ‘SELECT * FROM ‘.$postsTable.’ WHERE post_type = “page” OR post_type = “post” AND post_status = “publish”‘);

$wpdb post type and term query only works when there are no dashes or spaces in the term slug and title

In your code you are using “AND terms.name=”shorelineorwaterway” where I don’t think shorelineorwaterway is your term name, it could be your terms slug. So you can modify this by “AND terms.slug = ‘shorelineorwaterway’ and here inside inverted commas you can use hyphen. If you need to use term name then “AND terms.name=”Your Term Name” would … Read more