• Dashboard
    • Submit Ticket
    • Licenses
    • Login
  • Our Products
    • BuddyBuilder
    • Kleo
    • Typer
    • Seeko
    • SweetDate
    • BuddyApp
  • Services
    • VIP Support
    • WordPress Theme Installation Service
  1. Home
  2. SweetDate
  3. How to add a Populated Country List XPROFILE

How to add a Populated Country List XPROFILE

Hello everyone, this topic is for those who want to have an already populated country list to user xprofile fields instead of adding one by one.

Just edit the child theme file “functions.php” and paste the following code:

COPY CODE
/*
If you are using BP 2.1+, this will insert a Country selectbox.
Add the function to bp-custom.php and then visit .../wp-admin/users.php?page=bp-profile-setup
Remove this function after the field is created.
*/

function bp_add_custom_country_list() {
 
  if ( !xprofile_get_field_id_from_name('Country') && 'bp-profile-setup' == $_GET['page'] ) {
 
		$country_list_args = array(
		       'field_group_id'  => 1,
		       'name'            => 'Country',
		       'description'	 => 'Please select your country',
		       'can_delete'      => true,
		       'field_order' 	 => 2,
		       'is_required'     => false,
		       'type'            => 'selectbox',
		       'order_by'	 => 'custom'
 
		);
 
		$country_list_id = xprofile_insert_field( $country_list_args );
 
		if ( $country_list_id ) {
 
			$countries = array(
				"United States",			
				"Afghanistan",
				"Albania",
				"Algeria",
				"Andorra",
				"Angola",
				"Antigua and Barbuda",
				"Argentina",
				"Armenia",
				"Australia",
				"Austria",
				"Azerbaijan",
				"Bahamas",
				"Bahrain",
				"Bangladesh",
				"Barbados",
				"Belarus",
				"Belgium",
				"Belize",
				"Benin",
				"Bhutan",
				"Bolivia",
				"Bosnia and Herzegovina",
				"Botswana",
				"Brazil",
				"Brunei",
				"Bulgaria",
				"Burkina Faso",
				"Burundi",
				"Cambodia",
				"Cameroon",
				"Canada",
				"Cape Verde",
				"Central African Republic",
				"Chad",
				"Chile",
				"China",
				"Colombi",
				"Comoros",
				"Congo (Brazzaville)",
				"Congo",
				"Costa Rica",
				"Cote d'Ivoire",
				"Croatia",
				"Cuba",
				"Cyprus",
				"Czech Republic",
				"Denmark",
				"Djibouti",
				"Dominica",
				"Dominican Republic",
				"East Timor (Timor Timur)",
				"Ecuador",
				"Egypt",
				"El Salvador",
				"Equatorial Guinea",
				"Eritrea",
				"Estonia",
				"Ethiopia",
				"Fiji",
				"Finland",
				"France",
				"Gabon",
				"Gambia, The",
				"Georgia",
				"Germany",
				"Ghana",
				"Greece",
				"Grenada",
				"Guatemala",
				"Guinea",
				"Guinea-Bissau",
				"Guyana",
				"Haiti",
				"Honduras",
				"Hungary",
				"Iceland",
				"India",
				"Indonesia",
				"Iran",
				"Iraq",
				"Ireland",
				"Israel",
				"Italy",
				"Jamaica",
				"Japan",
				"Jordan",
				"Kazakhstan",
				"Kenya",
				"Kiribati",
				"Korea, North",
				"Korea, South",
				"Kuwait",
				"Kyrgyzstan",
				"Laos",
				"Latvia",
				"Lebanon",
				"Lesotho",
				"Liberia",
				"Libya",
				"Liechtenstein",
				"Lithuania",
				"Luxembourg",
				"Macedonia",
				"Madagascar",
				"Malawi",
				"Malaysia",
				"Maldives",
				"Mali",
				"Malta",
				"Marshall Islands",
				"Mauritania",
				"Mauritius",
				"Mexico",
				"Micronesia",
				"Moldova",
				"Monaco",
				"Mongolia",
				"Morocco",
				"Mozambique",
				"Myanmar",
				"Namibia",
				"Nauru",
				"Nepal",
				"Netherlands",
				"New Zealand",
				"Nicaragua",
				"Niger",
				"Nigeria",
				"Norway",
				"Oman",
				"Pakistan",
				"Palau",
				"Panama",
				"Papua New Guinea",
				"Paraguay",
				"Peru",
				"Philippines",
				"Poland",
				"Portugal",
				"Qatar",
				"Romania",
				"Russia",
				"Rwanda",
				"Saint Kitts and Nevis",
				"Saint Lucia",
				"Saint Vincent",
				"Samoa",
				"San Marino",
				"Sao Tome and Principe",
				"Saudi Arabia",
				"Senegal",
				"Serbia and Montenegro",
				"Seychelles",
				"Sierra Leone",
				"Singapore",
				"Slovakia",
				"Slovenia",
				"Solomon Islands",
				"Somalia",
				"South Africa",
				"Spain",
				"Sri Lanka",
				"Sudan",
				"Suriname",
				"Swaziland",
				"Sweden",
				"Switzerland",
				"Syria",
				"Taiwan",
				"Tajikistan",
				"Tanzania",
				"Thailand",
				"Togo",
				"Tonga",
				"Trinidad and Tobago",
				"Tunisia",
				"Turkey",
				"Turkmenistan",
				"Tuvalu",
				"Uganda",
				"Ukraine",
				"United Arab Emirates",
				"United Kingdom",
				"Uruguay",
				"Uzbekistan",
				"Vanuatu",
				"Vatican City",
				"Venezuela",
				"Vietnam",
				"Yemen",
				"Zambia",
				"Zimbabwe"
			);
			
			foreach (  $countries as $country ) {
				
				xprofile_insert_field( array(
					'field_group_id'	=> 1,
					'parent_id'		=> $country_list_id,
					'type'			=> 'option',
					'name'			=> $country,
					'option_order'   	=> $i++
				));
				
			}
 
		}
	}
}
add_action('bp_init', 'bp_add_custom_country_list');

 

USA States:

COPY CODE
/*
If you are using BP 2.1+, this will insert a state selectbox.
Add the function to bp-custom.php and then visit .../wp-admin/users.php?page=bp-profile-setup
Remove this function after the field is created.
 */

function bp_add_custom_state_list()
{

    if (!xprofile_get_field_id_from_name('state') && 'bp-profile-setup' == $_GET['page']) {

        $state_list_args = array(
            'field_group_id' => 1,
            'name' => 'state',
            'description' => 'Please select your state',
            'can_delete' => true,
            'field_order' => 2,
            'is_required' => false,
            'type' => 'selectbox',
            'order_by' => 'custom',

        );

        $state_list_id = xprofile_insert_field($state_list_args);

        if ($state_list_id) {

            $states = array(
                "Alabama",
                "Alaska",
                "Arizona",
                "Arkansas",
                "California",
                "Colorado",
                "Connecticut",
                "Delaware",
                "Florida",
                "Georgia",
                "Hawaii",
                "Idaho",
                "Illinois",
                "Indiana",
                "Iowa",
                "Kansas",
                "Kentucky",
                "Louisiana",
                "Maine",
                "Maryland",
                "Massachusetts",
                "Michigan",
                "Minnesota",
                "Mississippi",
                "Missouri",
                "Montana",
                "Nebraska",
                "Nevada",
                "New Hampshire",
                "New Jersey",
                "New Mexico",
                "New York",
                "North Carolina",
                "North Dakota",
                "Ohio",
                "Oklahoma",
                "Oregon",
                "Pennsylvania",
                "Rhode Island",
                "South Carolina",
                "South Dakota",
                "Tennessee",
                "Texas",
                "Utah",
                "Vermont",
                "Virginia",
                "Washington",
                "West Virginia",
                "Wisconsin",
                "Wyoming",
            );

            foreach ($states as $state) {

                xprofile_insert_field(array(
                    'field_group_id' => 1,
                    'parent_id' => $state_list_id,
                    'type' => 'option',
                    'name' => $state,
                    'option_order' => $i++,
                ));

            }

        }
    }
}
add_action('bp_init', 'bp_add_custom_state_list');

Blazing Fast Site Hosting & Maintenance

  • Welcome to SweetDate!
  • Theme Requirements
  • WordPress Installation
  • Install Theme & Setup
  • Search Form Setup for 3.0
  • Updating to SweetDate 3.4
  • Verify server configuration and theme requirements
  • How to manually update the theme
  • Theme Automatic Updates
  • BuddyPress overview
  • Elementor overview
  • bbPress overview
  • Memberships
  • Membership overview
  • rtMedia overview
  • Restrict website for non logged in members
  • Extended features
  • Paid Memberships Pro
  • Revolution Slider plugin
  • Woocommerce
  • Enabling BuddyPress Groups
  • GEO My WP + Sweetdate: Add a map search and location
  • Add link to element or button in Revolution Slider 6.x
  • Introduction to the child theme
  • How to Change the Search and Register Form Colors
  • Contact Page
  • Pages and Menu
  • Overriding a file with the child theme
  • How to add Members Stats Section using Elementor
  • Theme options overview
  • Import / Export Options
  • Contact and social settings
  • Buddypress settings
  • Styling options
  • Layout Settings
  • General Settings
  • Footer structure and widgets
  • Widgets and sidebar
  • Page Templates
  • Find Theme Purchase Code
  • Translate theme with Loco Translate
  • Multilingual setup using WPML plugin
  • Image Slider Shortcode
  • Icons Shortcode
  • Layout shortcodes
  • Recent groups Shortcode
  • Top members Shortcode
  • Member Statistics Shortcode
  • Buddypress User Data Shortcodes
  • Homepage status icon shortcode
  • Restrict content shortcode
  • Blog Articles Shortcode
  • Headings shortcodes
  • Video button shortcode
  • Posts carousel Shortcode
  • Pricing Table Shortcode
  • Panel Shortcode
  • Accordion Shortcode
  • Tabs Shortcode
  • Progress Bar Shortcode
  • Alert Shortcode
  • Buttons Shortcode
  • Missing Post Update Button on Buddypress ( Activity and Groups )
  • Changelog
  • Javascript Files
  • CSS Files and Structure
  • HTML Structure
  • Testimonials
  • My site is slow. How to speed up my website?
  • Included PSD Files
  • Post formats
  • Accordion Shortcode
  • RESPONSIVE guidelines
  • Theme Folder structure
  • GeoNames integration - City Autocomplete
  • How to add a Populated Country List XPROFILE
  • More Visible Discount Code Text (PMPRO Checkout)
  • How to Customize Women Online and Men Online Counters - WITHOUT ELEMENTOR
  • Full Width Profile Fields
  • How to move Search form to the right side of the screen
  • How to Delete the Link from the Website Logo
  • Search Results Show Wrong Gender - SOLUTION
  • Free Females Only or Free Males Only Membership Paid Memberships Pro
  • How to add Profile Fields under Member Name at Members Directory
  • Error 404 - Page not found
  • Change "SIGN UP" URL at Modal Popup
  • Troubleshooting an issue
BuddyBuilder is out. Total freedom to build online communities
SeventhQueen  - 2021 - Privacy Policy

Welcome to SeventhQueen Portal


Lost your password?

Don't have an account? Register now!

Forgot your details?



Wait, I remember now. Log In

Register your account

Sign up with Email
I have an account. Log In

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.