AI Verified

Name

Migrate BasePress -> BetterDocs: 3. Feedback

About

<p>Use these to migrate data from BasePress to BetterDocs, or clone them and customize to migrate to some other structure.</p> <p>Import all 4 snippets, then run them in order. This will handle docs, tags, categorys, meta, analytics, and search logs. It handles feedback as well, but BasePress didn't keep it logged over time, so you get one lump sum inserted to the current date for each doc.</p> <ol> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-1">Migrate Docs, Categories, Tags &amp; Meta.</a></li> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-2">Analytics</a></li> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-3">Feedback</a></li> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-4">Search Logs</a></li> </ol>

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

<p>Use these to migrate data from BasePress to BetterDocs, or clone them and customize to migrate to some other structure.</p> <p>Import all 4 snippets, then run them in order. This will handle docs, tags, categorys, meta, analytics, and search logs. It handles feedback as well, but BasePress didn't keep it logged over time, so you get one lump sum inserted to the current date for each doc.</p> <ol> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-1">Migrate Docs, Categories, Tags &amp; Meta.</a></li> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-2">Analytics</a></li> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-3">Feedback</a></li> <li><a href="https://codesnippets.cloud/snippet/Code-Atlantic/migrate-basepress-to-betterdocs-step-4">Search Logs</a></li> </ol>

Codevault

Code-Atlantic

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://code-atlantic.com

Snippet Source:

https://danieliser.com

History

Last modified:

14/10/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Migrate BasePress -> BetterDocs: 3. Feedback

 
                    
1function migrate_feedback_data() {
2 global $wpdb;
3 
4 $analytics_table = "{$wpdb->prefix}betterdocs_analytics";
5 
6 // Get all post_ids that have feedback data
7 $post_ids = $wpdb->get_col("SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'basepress_votes'");
8 
9 $processed_posts = get_option('processed_knowledgebase_posts', []);
10 
11 foreach ($post_ids as $old_post_id) {
12 // Check if the old post id exists in the processed_posts array.
13 if (isset($processed_posts[$old_post_id])) {
14 $new_post_id = $processed_posts[$old_post_id];
15 } else {
16 continue; // Skip if not found in the processed_posts array.
17 }
18 
19 // Get feedback data
20 $votes = get_post_meta($old_post_id, 'basepress_votes', true);
21 if (!$votes) continue; // Skip if no feedback data found
22 
23 // Fetch the post's last updated date or the post date if that's not available.
24 $post_date = $wpdb->get_var($wpdb->prepare("SELECT COALESCE(post_modified, post_date) FROM {$wpdb->posts} WHERE ID = %d", $old_post_id));
25 
26 // Prepare data for the new table
27 $data = [
28 'post_id' => $new_post_id,
29 'happy' => isset($votes['like']) ? (int) $votes['like'] : 0,
30 'sad' => isset($votes['dislike']) ? (int) $votes['dislike'] : 0,
31 'created_at' => date('Y-m-d', strtotime($post_date))
32 ];
33 
34 // Insert data into the new table
35 $wpdb->insert($analytics_table, $data);
36 }
37}
38 
39add_action( 'init', 'migrate_feedback_data', 11 );

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

2

Google Tag Manager Head Part

Added: 1 year ago

Last Updated: 1 year ago

Google Tag Manager Head Part

General

AI Verified

0

Image in RSS Feed from Post Content

Added: 1 year ago

Last Updated: 1 year ago

You can set first image from post content to show in RSS feeds

General

AI Verified

1

Enable Fluent Forms login form capability

Added: 1 year ago

Last Updated: 1 year ago

Fluent forms does not allow the creation of a login form natively at the time of writing. However, this snippet enables that function.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

0

Migrate BasePress -> BetterDocs: 2. Analytics

Added: 4 months ago

Last Updated: 4 months ago

<p>Use these to migrate data from BasePress to BetterDocs, or clone them and customize to migrate to some other structure.</p> <p>Import all 4 snippets, then run them in order. This will handle docs,...

General

AI Verified

0

Migrate BasePress -> BetterDocs: 4. Search Logs

Added: 4 months ago

Last Updated: 4 months ago

<p>Use these to migrate data from BasePress to BetterDocs, or clone them and customize to migrate to some other structure.</p> <p>Import all 4 snippets, then run them in order. This will handle docs,...

General

AI Verified

0

Migrate BasePress -> BetterDocs: 3. Feedback

Added: 4 months ago

Last Updated: 4 months ago

<p>Use these to migrate data from BasePress to BetterDocs, or clone them and customize to migrate to some other structure.</p> <p>Import all 4 snippets, then run them in order. This will handle docs,...