Fetch data from external database to WordPress website - wordpress

I am new to WordPress, I have an old website containing a simple database to my diner's menu, I am switching my website to WordPress and I need to use my old database, is their anyway I can use both databases? The one already in WordPress and my own database?

You can try something like this or refer to this forum: https://wordpress.org/support/topic/multiple-databases-16/
function seconddb() {
global $seconddb;
$seconddb = new
wpdb('Username','password','database name','localhost');
}
add_action('init','seconddb');

Related

Gravity Forms - Global forms for multisite

I've a WordPress multi-site network with 20+ sites. and i'm using gravity forms for Contact/Signup/Subscription forms. I would like to create global form for my wordpress multisite installation. Is it possible that gravity forms save the form entries only into the main/parent site? I've tried using switch_to_blog() in children sites. but it is not working.any help would be appreciated :)
If you duplicate the form into all sites, you can make them all send their data to the main site by including this on the 'child' sites:
$formId = 1; //Put your form id here
add_filter('gform_confirmation_'.$formId, 'gform_confirmation', 10, 4);
function gform_confirmation($confirmation, $form, $entry, $is_ajax) {
//Switch to Main site
switch_to_blog(1);
//Insert the entry into the main site
$new_entry_id = \GFAPI::add_entry($entry);
//Switch back
restore_current_blog();
//Tidy up by deleting the entry from THIS site
$result = GFAPI::delete_entry($entry['id']);
return $confirmation;
}
Gravity forms stores data based on blog database table prefix,
in multisite all sites uses the same database but data are separated based on table prefix, the prefix are something like, wp_1_, wp_2_, wp_3_.....
if you have a site, like my.blog1.com with table prefix, wp_1_, gravity form store all the form entries of my.blog1.com to wp_1_rg_lead, wp_1_rg_lead_detail, wp_1_rg_lead_detail_long,
Now if you want to save those details on your parent install, you need to play around with the database and modify gravity form using hooks like gform_pre_submission or gform_after_submission
This post might help
http://www.endocreative.com/save-gravity-forms-data-custom-database-table/

Front End of Wordpress Plugin

This is my first plugin that i am developing. I have only one file in my plugin folder which has all the code that is handling my admin part. I have my own custom tables. I'm not using any wordpress table for it.
Structure:
plugin/amt
amt.php (This file has all the code which is dealing with admin part)
js/amt.js
Now I have got amt.php file working for my admin part. It is retrieving and saving data into the database. Till here its all fine.
Now, I want to add some functionality in the plugin which will be shown on frontend of the website. Please guide me, how can this be done? I could think of following options:
Add front end code in amt.php as well and use some kind of short code to display on front end of website under 'Sample Page'.
Need to create a new folder/file for front end?
I'll be thankful if some one can guide me please.
I have got it working with the help of short code. Here is what i did. added this code in my main plugin file i.e: amt.php
add_shortcode( 'clan', 'clan_fn' );
function clan_fn() { }
Create a new page from word press admin and simply call the short code as below and it will display what ever functionality you add in clan_fn.
[clan]

Templates and pulling data from my own database (not wordpress one)

I'm pretty new to wordpress. I have read a lot about templates, template pages, etc... and I would really apreciate if someone could confirm my thoughts, ideas about how to build my Homepage with wordpress (I won't be using it for blooging, but my enterprise webpage).
The main problem is that I need to have a page, where a little list of items will be shown. After one of them is clicked another page will be shown with information about the item like a pic, short description, etc... etc... This Item information page will be using a template page where data from my own CMS database has to be inserted in the template holes.
All examples I have seen in wordpress are about pushing data in wordpress database and showing it using WP API. But, what about if I just want to use wordpress as a template system, with all its plugins, etc... and pull the data needed to be shown from another database (our CMS)?. Could anyone suggest best practices for this, or a better aproach?.
Thanks in advance.
is your wordpress database in the same database as your own?
ie: you can access the wp tables along with all your other tables?
if so you can use the wp api, to connect,
using the normal connection methods..
if the tables are not in the same database but located under the same account on your host, you could use the same method shown in this thread...
$mydb = new wpdb('username','password','database','localhost');
$rows = $mydb->get_results("select Name from my_table");
echo "<ul>";
foreach ($rows as $obj) :
echo "<li>".$obj->Name."</li>";
endforeach;
echo "</ul>";
if the database is in another location, outwith the current server just change the localhost to your server ip and port to connect, ie:
$mydb = new wpdb('username','password','database','192.168.1.1:6807');
good luck
Marty

Hide other domains' menus from node edit form on a Drupal site using domain access

I'm in the process of making some improvements to a live Drupal site that's using the Domain Access module to run a number of microsites. I'm trying to find a way of restricting the menus a user can post content to from the node edit screen. A user on one of the domains should only be able to post content to menus associated with that domain.
Is there a simple way of achieving this? I'm guessing there are some hooks I could use, but so far I have been unable to identify them. I'd prefer not to have to install further modules to achieve this and to be able to add some code to the current site to alter the forms. The site is struggling with the large number of modules we've had to install on it already.
According to the readme for the module, you need to set some specific permissions in user management:
To enable this feature, you should grant the 'edit domain nodes' and
(optionally) the 'delete domain nodes' permission to some roles. Then assign
individual users accounts to specific domains to assign them as Domain Editors.
From my experience many moons ago with the module, you can check the global $user object and figure out what domains the user should have access to. You can then use a form alter to remove any options from the select box that you don't want them seeing. As always with Drupal though, it's better to let someone else write the code - so if the Domain module provides this functionality, use it!
Here is some updated code for Drupal 7:
/**
* Implements hook_form_FORM_ID_alter().
*/
function MYMODULE_form_page_node_form_alter(&$form, &$form_state) {
global $_domain;
if (isset($_domain['domain_id'])) { // only display domain's primary links
$menus[domain_conf_variable_get($_domain['domain_id'], 'menu_main_links_source')] = $_domain['sitename'].' Main menu';
}
if (isset($menus)) {
$options = menu_parent_options($menus, $form['#node']->type);
$form['menu']['link']['parent']['#options'] = $options;
}
}
Eventually found a way of fixing this for the particular project I have been working on: in module_form_alter I've added the following:-
global $_domain;
if (isset($_domain['domain_id'])) { // only display domain's primary links
$menus[domain_conf_variable_get($_domain['domain_id']
,'menu_primary_links_source')] = $_domain['sitename'].' Primary links';
}
if ( isset($menus) ) {
$options = menu_parent_options($menus, $form['menu']['#item']);
$form['menu']['parent']['#options'] = $options;
}
This restricts the menu options to just the current domain's primary links menu which is just what we wanted.
Thanks to Fabian who pointed me in the right direction earlier.

Changing paths to images in Wordpress

I recently moved a friends blog onto his new web hosts but unfortunately the images are not working.
This is due to the old host having the following path for images:
http://www.example.com/blog/wp-content/uploads/2009/07/imagename.jpg
The new host uses a different layout and has this path for the file:
http://www.example.com/wp-content/uploads/2009/07/imagename.jpg
'Blog' has been removed.
Does anyone know the easiest way to fix this issue?
Use this query on your database:
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com/blog','http://www.new-domain.com');
I've found this tutorial on Exporting and Importing Wordpress very helpful in such situations.
Search RegEx is a good plugin to be able to search and replace with Grep through all posts and pages. Also look in template files for hardcoded links in the form of <>php bloginfo(); ?> for the unneeded /blog/ in the path.
Search replace is a good plugin as well as Search RegEx. Especially if your data to replace is widespread throughout your site. http://wordpress.org/extend/plugins/search-and-replace/

Resources