Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : global $wpdb; $posts = $wpdb->get_results( 'SELECT ID, post_title AS title, post_excerpt AS excerpt FROM '.$wpdb->posts.' WHERE post_type = "post" AND post_status = "publish" ORDER BY post_date DESC LIMIT 4' );
I have this folder here that contains the multiple sql files and I want to convert them to Gzip using 7Zip. You can only see 10 files but there are 254 files since it is a large database. I tried the following command for /f %%X in (*.sql) do "c:\Program Files\7-Zip\7z.exe" a -tgzip "%%X.zip" "%%X" but command prompt says "The system cannot find the file *.sql." Even the command with no extension such as (*.) says the same thing that …
So, basically, I want to remove trailing slashes from specific domain urls. For example: https://www.example.com/here/postname/ into https://www.example.com/here/postname I have 10.4.21-MariaDB which should support REGEXP_REPLACE function. This is my query: UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, '(http\S+)\/(\s|$)', '$1'); or this one more specifically: UPDATE wp_posts SET post_content = REGEXP_REPLACE(post_content, '(https:\/\/www\.example\.com\/here\/\S+)\/(\s|$)', '$1'); which according to regular expressions should work: https://regex101.com/r/slLbgg/1 What am I doing wrong? Any kind of help is appreciated! :) This is the result:
I would like to get a list of user_nicenames and the ID. But not all the usernames which is what i'm getting now. I understand I should use the % before and after the $name only nothing seems to be working. This is the only way to get some output I found till now; global $wpdb; //get access to the WordPress database object variable //get names of all users $name = $wpdb->esc_like(stripslashes($_POST['name'])).'%'; //escape for use in LIKE statement $sql = …
I struggled with this a long time! Can anyone help me? My plugin is not creating a database table once activated. The following code is in the main plugin file. function woocq_activate() { global $wpdb; $table_name = $wpdb->prefix . 'woocq'; $sql = "CREATE TABLE $table_name ( id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, name VARCHAR NOT NULL, message TEXT NOT NULL, question_id INT NOT NULL, product_id INT DEFAULT NULL, timestamp BIGINT NOT NULL, PRIMARY KEY (id) );"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( …
i just want to create a custom Table in my WordPress database and i saw many php functions to deal with that my question now is : can i just create them with an sql command and for what do i need to keep an eye on ?
I have referred to various articles on Stack Overflow and external sources but somehow am unable to get answer for this. I would like to read a table from MySQL workbench database into a dataframe in colab. $1^{st}$ Method: In this method, first line of code is successfully executed. Note: I have hidden database, table and password name for security reasons. Source - USER = 'root' PASSWORD = 'PASSWORD' DATABASE = 'DATABASE' TABLE = 'TABLE' connection_string = f'mysql+pymysql://root:PASSWORD/DATABASE' engine = …
I have a custom post type with custom fields(advanced custom fields plugin). one of the custom fields named program_id. i can`t understand how to get all of the posts in that CPT where the ACF field value is x, and only them. i read ACF guide but i always get all of the post. $student_query_args = [ 'post_type' => 'student_list', 'post_status' => 'publish', 'posts_per_page' => 100, 'order' => 'DESC', 'meta_query' => [ 'key' => 'program_id', 'value' => 5317, ], ]; …
I want to fetch multiple posts with categories and tags currently I'm using this query: $pagesize = 20; $pageNumber = 1; $mysql = mysqli_query($con,"SELECT p.post_title, p.ID, p.post_content, p.post_date, p.post_name as url, t.name as category_name FROM wp_posts p, wp_terms t, wp_term_relationships r, wp_term_taxonomy tt WHERE p.post_status='publish' AND tt.taxonomy = 'post_tag' AND p.id=r.object_id AND r.term_taxonomy_id=tt.term_taxonomy_id AND tt.term_id = t.term_id ORDER BY p.post_date desc LIMIT ".(int)($pageNumber*$pageSize).",".(int)$pageSize."") or die ("error".mysqli_error($con)); The mysqli-connection works. But when I run this code, I only get a blank …
Is it possible to create a table with the wpdb::prepare function? I read the documentation and tried to find examples but there where none that helped me. Even creating a table with prepare doesn't give me any useful examples on Google. Currently I'm creating my table like this: public function createTableFromFields( $tablename, $fields ) { // $wpdb = $this->db; $tablename = $wpdb->prefix . $tablename; $sql = 'CREATE TABLE IF NOT EXISTS ' . $tablename . ' (id INT(6) UNSIGNED AUTO_INCREMENT …
I am writing some SQL queries to get post data out of a database for certain posts (so WP functions are not an option). I am trying to get post IDs, post URLs, post featured image URLs and associated alt text for the featured images. Alt text is held in the postmeta table with the meta_key '_wp_attachment_image_alt'. The query below works for everything except alt text. I am confident I need to use a left join because I want all …
I have two Dataframes facts: columns: data, start_date and end_date holidays: column: holiday_date What I want is a way to produce another Dataframe that has columns: data, start_date, end_date and num_holidays Where num_holidays is computed as: Number of days between start and end that are not weekends or holidays (as in the holidays table). The solution is here if we wanted to do this in PL/SQL. Crux is this part of code: --Calculate and return the number of workdays using …
I need to create a table in hive (or Impala) by reading from a csv file (named file.csv), the problem is that this csv file could have a different number of columns each time I read it. The only thing I am sure of is that it will always have three columns called A, B, and C. For example, the first csv I get could be (the first row is the header): ------------------------ | X | Y | A | …
A classifieds list site have only 3 criterias when searching products: the common search, category and region (for ZIP, city or full address) It's not enough and I really need to include a basic price system, so users can set a price range before searching. Looking at the theme files, I found the function for different queries, based in one or more of those criterias. The smaller is the query for only category, so I'll take it as example: elseif …
I have set up a plugin that because of the amount of data being used I set up a custom table and have extended the WP_List_Table class. I know that is not recommended, but Custom Post Types just won't offer what I need. I plan on including a copy of the WP_List_Table class when releasing this project to prevent any unwanted bugs... Anyhow, I have the following code and have went through a lot of tutorials on extending the WP_List_Table …
I am new in programming, and the sql is absolutely stranger for me. I create today a new meta_key on my multisite, but when I use this in a query, my site will be horrible slow... I read (here: https://css-tricks.com/finding-and-fixing-slow-wordpress-database-queries/), that need for me creating a sql index for the meta_key, and this will doing incredibly faster my site... So here this sql command: CREATE INDEX wp_postmeta_csstricks ON wp_postmeta (meta_key) If my meta_key is _my_first_meta, I can use this code?: …
I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class WP_Query_Posts_User_Follows extends WP_Query { function __construct($args=array()) { if ( !empty($args['followed_by']) ) { $this->followed_by = $args['followed_by']; add_filter('posts_where', array($this, 'posts_where')); } parent::query($args); } function posts_where($where) { global $wpdb; $table = $wpdb->prefix . 'post_followed_by'; $where .= $wpdb->prepare(" AND ID IN (SELECT post_id FROM $table WHERE user_id = %d)", $this->followed_by); return …
Is there no mechanism which purges old options from the DB? I tried a few plugins in the past and I found out that there are a few pretty long option strings which are set to autoload but IMHO not used at all - as I'm not using those plugins anymore. So I guess it makes sense to remove those options completely - but I'm not 100% sure whether I miss some implications? Am I mistaken, or this the unfortunate …
I don`t know coding. I recently my website stop to work properly. I get this error on the top of on every page loaded. Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in /home/nortoniq/public_html/mywebsiteaddress.com/wp-content/themes/porto/functions.php on line 60 Anybody can help me with this error? much appreciate
I have FHIR-formatted data (Fast Healthcare Interoperability Resources), that I've converted to CSV using the npm package ndjson-to-csv, and on first glance, this seems useable for ML experimentation, as long as I first join the data on the relevant properties. I could spend a while going through the approximately 12 resource types (like Device, Patient, Condition, etc) to see which resource types are joinable and if so on what property. However, I was wondering if anyone has a cheat sheet …