RSS Issue - Drupal to WordPress Migration - wordpress

I'm using the script from this site to migrate a Drupal database to WordPress. It seems to work ok, except for the RSS feed which returns an HTTP 304 error when I try to access it.
I think that the problem is somewhere in the following lines:
TRUNCATE TABLE wordpress.wp_comments;
TRUNCATE TABLE wordpress.wp_links;
TRUNCATE TABLE wordpress.wp_postmeta;
TRUNCATE TABLE wordpress.wp_posts;
TRUNCATE TABLE wordpress.wp_term_relationships;
TRUNCATE TABLE wordpress.wp_term_taxonomy;
TRUNCATE TABLE wordpress.wp_terms;
When the script empties the WordPress database, RSS feeds stop working. However, if I carried out the import of blog posts without emptying the above tables, the feeds seem to work ok.
Any thoughts?

In the above line i think there is no any problem. So you have to check out all the code:
Database Conversion Table
Drupal 6.x Table(s) WordPress 2.9x Equivalent
term_data, term_hierarchy wp_terms
node, node_revisions `wp_posts
term_node wp_term_relationships
comments wp_comments
Truncate WordPress Tables
First, I needed to remove any data that is currently in certain wordpress tables so I could work with a fresh slate.
Note: By default when you install wordpress all tables are prefixed with wp_ unless you changed it to something else. The below queries will need to be modified if you used anything else other than wp_.
TRUNCATE TABLE wp_comments;
TRUNCATE TABLE wp_postmeta;
TRUNCATE TABLE wp_posts;
TRUNCATE TABLE wp_term_relationships;
TRUNCATE TABLE wp_term_taxonomy;
TRUNCATE TABLE wp_terms;
Import Taxonomy Terms
The next sets of queries imports taxonomy terms.
Note: Table names pre-pended with drupal. needs to be the actual name of your drupal database. You will need to change this to whatever you have your drupal database named.
INSERT INTO wp_terms (term_id, name, slug, term_group)
SELECT d.tid, d.name, REPLACE(LOWER(d.name), ' ', '-'), 0
FROM drupal.term_data d
INNER JOIN drupal.term_hierarchy h
USING(tid);
By default, WordPress has several taxonomy types available; categories, post_tag, and link_category. In my Drupal instance I used taxonomy primarily as tags, but you may have a different need. You may need to modify the 3rd line in the below query depending on how you want taxonomies imported:
Categories: category
Link Categories: link_category
Post Tags: post_tag
INSERT INTO wp_term_taxonomy (term_taxonomy_id, term_id, taxonomy,
description, parent)
SELECT d.tid, d.tid, 'post_tag', d.description, h.parent
FROM drupal.term_data d
INNER JOIN drupal.term_hierarchy h
USING(tid);
Import Post Content
Drupal allows for custom post types, while as of WordPress 2.9x, custom post types are only available via plugins. You can use the below query unmodified and it will convert all stories to posts, and everything else will transfer over as is. If you need to convert additional post types, you can add additional case statements.
Example:
WHEN 'book' THEN 'post'
I also adjusted the query so that ‘post_date_gmt’ would be populated correctly based on my GMT offset of -6:00 (Central Time). If you are in a different timezone you will need to adjust FROM_UNIXTIME(created+21600) to subtract or add correctly based on your location.
INSERT INTO
wp_posts (id, post_date, post_date_gmt, post_content, post_title,
post_excerpt, post_name, post_type, post_modified)
SELECT DISTINCT
n.nid, FROM_UNIXTIME(created),
FROM_UNIXTIME(created+21600), body, n.title, teaser, LOWER(n.title),
(CASE n.TYPE
WHEN 'story' THEN 'post'
ELSE n.TYPE
END) AS TYPE,
FROM_UNIXTIME(changed)
FROM drupal.node n, drupal.node_revisions r
WHERE n.vid = r.vid;
Import Post and Taxonomy Relationships
INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
SELECT nid, tid FROM drupal.term_node;
Category Count Updating
UPDATE wp_term_taxonomy tt
SET COUNT = (
SELECT COUNT(tr.object_id)
FROM wp_term_relationships tr
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
);
Import Comments
INSERT INTO wp_comments (comment_post_ID, comment_date,
comment_content, comment_parent, comment_author,
comment_author_email, comment_author_url, comment_approved)
SELECT nid, FROM_UNIXTIME(TIMESTAMP), comment, thread,
name, mail, homepage, STATUS
FROM drupal.comments;
Update Comment Count
UPDATE wp_posts
SET comment_count = (SELECT COUNT(comment_post_id)
FROM wp_comments
WHERE wp_posts.id = wp_comments.comment_post_id);
Update Post Slugs
Drupal’s URL aliases is equivalent to WordPress’ permalinks. Drupal has a much more aggressive title sanitation than WordPress. I wanted the ability to keep my titles the same for SEO reasons when migrating over to WordPress.
In order to keep my old titles, I need to hook into WordPress’ title sanitation with similar rules to Drupal. The below code will need to be placed somewhere in the functions.php file of your current theme.
add_filter('sanitize_title', 'my_sanitize_title');
function my_sanitize_title($title) {
$title = preg_replace('/\b(a|an|as|at|before|but|by|for|from|is|in|into|like|of|off|on|onto|per|since|than|the|this|that|to|up|via|with)\b/i', '', $title);
$title = preg_replace('/-+/', '-', $title);
$title = trim($title, '-');
return $title;
}
You will need to save the below code to a file i.e. “fix-slugs.php” in your main WordPress directory and run it through your browser.
< ?php
require_once('wp-load.php');
$posts = $wpdb->get_results(
"SELECT ID, post_title, post_name FROM $wpdb->posts"
);
$count = 0;
$ignored = 0;
$errors = 0;
foreach($posts as $post) {
if(strcmp($slug = sanitize_title($post->post_title), $post->post_name) !== 0) {
$wpdb->show_errors();
if(($result = $wpdb->query("UPDATE $wpdb->posts SET post_name='$slug' WHERE ID=$post->ID")) === false) {
$errors++;
} elseif($result === 0) {
$ignore++;
} else {
$count++;
}
} else {
$ignored++;
}
}
echo "<strong>$count post slug(s) sanitized.</strong><br />";
echo "$ignored post(s) ignored.<br />";
echo "$errors error(s).<br />";
If you were following along with this tutorial, I’ve made a few changes based on my Drupal setup using WordPress database description as a reference when I ran into issues. There may be some additional steps to be completed if you uploaded images through Drupal’s interface, but the above queries were able to successfully migrate my data from Drupal to WordPress.

Using HtmlAgilityPack for Visual Studio helped a lot in quickly building an importer to go through each of Drupal's posts and add them to Wordpress using XMLRPC. Since Drupal has two separate columns for the post content and post teaser, it is much better this way to import Drupal into Wordpress so that you can add <!--more--> tags on the fly.

Related

how to insert checkout page custom field value wp_posts table in wp

I have added the custom field check out page. I want to add this custom field's value to the order list in the wp_posts table
Here I have added a Row delivery_option in wp_posts table
http://prntscr.com/rbdjcy
Thanks
in WP you dont need/shouldn't change wp tables are this will be overwritten in the next update/upgrade. To save those values use WP php functions (forget database as WP functions will handle saving/getting for you from meta table)
So to add or update use
update_post_meta($post_id, $meta_key, $meta_val);
here meta key will be "delivery_option" and meta_value will be anything you want to store. $post_id will be current post/product id , you can get as get_the_ID(); Also if you do not want this custom field show up in WP default custom fields metaboxes, you may prefix your meta key with "_" underscore so "delivery_option" will be become "_delivery_option"
Then to get this data back :
$delivery_val = get_post_meta($post_id, 'delivery_option', true);
or
$delivery_val = get_post_meta($post_id, '_delivery_option', true); //_used to keep it hidden from WP default custom fields metaboxes
Source:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://developer.wordpress.org/reference/functions/update_post_meta/
https://developer.wordpress.org/reference/functions/add_post_meta/
PS. Even there is add_post_meta , normally we use update_post_meta as it will add if no value exists or will update if any old value exists.

Wordpress - showing last uploaded images, but only from a specific custom post type

I have a Wordpress-powered website with several custom post types, and I'm struggling to find a way to load the latest uploaded images from one of the custom post types only.
In other words, I know how to ask for the most recent 4 images added to the Wordpress media library, but I can't find a way to filter the attachments depending of the post type of their parent page (in this case, show only the images uploaded to 'Image Gallery' posts - not regular posts, not 'Video Gallery' posts, etc).
It feels like a very basic question, but for some reason I can't get this work and I'm really frustrated. Is there any way to get the post type of the post parent in the query? Or I should approach this issue from another angle?
I don't believe it's possible to use WP_Query to filter based on the post type of the parent. The most straightforward way around this is to use SQL and $wpdb->get_results() directly. This will also bypass all built in caching, etc so think about how your implementation will be used.
global $wpdb;
// the SQL statement to only fetch the N last attachments
$sql = <<<SQL
SELECT attachments.*
FROM {$wpdb->posts} attachments
-- join the parent post based on the parent_post value to filter by cpt
JOIN {$wpdb->posts} post
ON post.ID = attachments.post_parent
AND post.post_status = 'publish'
-- pass in the custom post type
AND post.post_type = %s
WHERE
-- only fetch images, double percents for prepare()
attachments.post_mime_type LIKE 'image%%'
ORDER BY attachments.post_date DESC
-- pass in the number to fetch
LIMIT %d
SQL;
$cpt = "your_custom_post_type";
$limit = 4;
$attachments = $wpdb->get_results( $wpdb->prepare( $sql, $cpt, $limit ) );
foreach ( $attachments as $attachment ){
// $attachment will have all the rows from the posts table.
$id = $attachment->ID;
}

Prevent execution of $wpdb->get_var if post is in a specific taxonomy

in a site of mine I Bulk import data (published as posts) from a json file, and to prevent post duplication, I do the following query on the wp db:
$identificatore = $deals->uuid;
$output = $wpdb->get_var($wpdb->prepare("SELECT count(id)
FROM $wpdb->posts wpo, $wpdb->postmeta wpm
WHERE wpo.ID = wpm.post_id
AND wpm.meta_key = 'deal_id'
AND wpm.meta_value = '$identificatore'"));
if(empty($output)) {
// retrieve data from json and publish as post
}
The problem:
When the blog have 1500/2000 posts published no matter, but when it have 10000/15000, the db query are longer then 15/20 seconds
In my mind what I think to do is do a preliminary check of the post, and check if is under a term "sold out" in the taxonomy "status", and if in that taxonomy jump the query to check if there is a custom fields with the value "$identificatore".
However if you know another way most light to prevent the posts duplication with "wp_insert_post" I'm here and I'm waiting for your help
Thanks

Wordpress wpdb query issue - how to filter out revisions?

Can someone tell me how to modify the code below so that it filters out revisions? I tried using revision deletion plugins but they only work for revisions of posts or pages... not custom post types.
<?php
global $wpdb;
global $post;
$review_id = $post->ID;
if (get_post_type($review_id) == "features") {
$assoc_id = get_post_meta($review_id, "associated_hosts_value", true);
$review_id = intval($assoc_id);
}
$assoc = $wpdb->get_col("SELECT DISTINCT post_id from wp_postmeta WHERE (meta_key='associated_hosts_value') AND ((meta_value LIKE ',{$review_id},%') OR (meta_value LIKE '%,{$review_id},%') OR (meta_value = '{$review_id}') OR (meta_value LIKE '%,{$review_id}'));");
Revision is stored in wp_posts under the post_type column, so you will need to inner join on wp_posts and query for a post_type NOT IN ('revision'):
"SELECT DISTINCT post_id from {$wpdb->postmeta} INNER JOIN {$wpdb->posts} ON ID = post_id WHERE post_type NOT IN ('revision') ..."
By the way, inserting raw SQL queries in to get_col is a bad practice, as it leaves you vulnerable to SQL injections. Use $wpdb->prepare() as shown here:
http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks
Note that you will need to escape the % used in the LIKE statements by changing them to %% to work within prepare().
Also, you shouldn't hard code WP table names in to your query statements. The wpdb class stores table names for use in constructing your queries, i.e. $wpdb->posts, $wpdb->postmeta. Using these assures that your plugin will always query the correct WP tables. Try your code in a multi site installation to find out why this is important.

Searching custom taxonomies in wordpress

Want to know is there any plugin/hack available for searching custom taxonomies in wordpress?
Directions for any idea will be great.
How about this?
function search_by_tax_filter(&$query)
{
if ($query->is_search)
$query->set('taxonomy', 'taxonomy_name');
}
add_action('parse_query', 'search_by_tax_filter');
Tricky business... This will get you started, this queries the top five tags (taxonomy: post_tag)...
// query the top five tags
$sql = '
SELECT wt.term_id ti,wt.name, wtt.count tc,wtr.term_taxonomy_id tti, wtr.object_id oi
FROM wp_terms wt
INNER JOIN wp_term_taxonomy wtt ON wt.term_id = wtt.term_id
INNER JOIN wp_term_relationships wtr ON wtr.term_taxonomy_id = wtt.term_taxonomy_id
LEFT JOIN wp_posts wp ON wp.ID = wtr.object_id
WHERE taxonomy = \'post_tag\'
GROUP BY name
ORDER BY count DESC LIMIT 0 , 5
';
I've recently developed a plugin that provides custom taxonomy filtering through front-end forms (with dropdowns and an optional text input):
Advanced Custom Post Search
It runs off of its own results page and doesn't directly tie in with the default search.php, nevertheless its still very flexible and allows you to override the plugin pages in your theme.

Resources