$authors = $newsitem->get_item_authors();
if( !empty( $authors ) ){
$facebook_author .= ',' .get_user_meta( $authors[0]->ID, 'eco_author_social_profile', true );
}
Trying to concat multiple authors in a fb share
You can try with implode
<?php
$authors = $newsitem->get_item_authors();
$facebook_authors = array()
if( !empty( $authors ) ){
$facebook_authors[] = get_user_meta( $authors[0]->ID, 'eco_author_social_profile', true );
}
$facebook_author = implode(",", $facebook_authors);
?>
You can also do this with your code
$authors = $newsitem->get_item_authors();
if( !empty( $authors ) ){
$facebook_author .= ',' .get_user_meta( $authors[0]->ID, 'eco_author_social_profile', true );
}
$facebook_author = ltrim($facebook_author, ",");
Related
I'm using a WordPress theme which has 3 different taxonomies. Country, State, City. So there are no parent child categories.
**What I'm trying to achieve:
**
On each state archive, I'm trying to show a list of cities and areas (each terms) which have a relationship with that state.
On each city archive, I want to show other cities (each terms) which have the same state.
This is how the theme currently saves the post meta for state, city and area:
// State
if( isset( $_POST['administrative_area_level_1'] ) ) {
$listing_state = sanitize_text_field( $_POST['administrative_area_level_1'] );
$state_id = wp_set_object_terms( $listing_id, $listing_state, 'listing_state' );
$homey_meta = array();
$homey_meta['parent_country'] = isset( $_POST['country'] ) ? $_POST['country'] : '';
if( !empty( $state_id) ) {
update_option('_homey_listing_state_' . $state_id[0], $homey_meta);
}
}
// City
if( isset( $_POST['locality'] ) ) {
$listing_city = sanitize_text_field( $_POST['locality'] );
$city_id = wp_set_object_terms( $listing_id, $listing_city, 'listing_city' );
$homey_meta = array();
$homey_meta['parent_state'] = isset( $_POST['administrative_area_level_1'] ) ? $_POST['administrative_area_level_1'] : '';
if( !empty( $city_id) ) {
update_option('_homey_listing_city_' . $city_id[0], $homey_meta);
}
}
// Area
if( isset( $_POST['neighborhood'] ) ) {
$listing_area = sanitize_text_field( $_POST['neighborhood'] );
$area_id = wp_set_object_terms( $listing_id, $listing_area, 'listing_area' );
$homey_meta = array();
$homey_meta['parent_city'] = isset( $_POST['locality'] ) ? $_POST['locality'] : '';
if( !empty( $area_id) ) {
update_option('_homey_listing_area_' . $area_id[0], $homey_meta);
}
}
Any advice is appreciated.
Thanks.
I have created dynamic add / remove file field to insert image in database. But somehow it is not working properly. Following is my code...
$member_image_names = array_map( 'sanitize_file_name', $_FILES['member_image']['name'] );
foreach ( $member_image_names as $member_image_name ) {
if ( empty( $member_image_name ) ) {
global $wpdb;
$project_id = $_SESSION['project_id'];
$project_member_details = $wpdb->get_var( $wpdb->prepare( "SELECT project_members FROM wpxa_orocox_project_members WHERE project_id = %d", $project_id ) );
$project_member_detail = json_decode( $project_member_details, true );
$member_image_newname = $project_member_detail['member_image'];
} else {
$member_image_ext = strtolower( end( explode( '.', $member_image_name ) ) );
$member_image_newname[] = get_current_user_id() . $_SESSION['project_id'] . "_" . time() . "_" . mt_rand() . "." . $member_image_ext;
}
$member_details->member_image = $member_image_newname;
$member_details_encode = wp_json_encode( $member_details );
global $wpdb;
$members_result_update = $wpdb->update( 'wpxa_project_members',
array( 'project_members' => $member_details_encode ),
array( 'project_id' => $_SESSION['project_id'] ),
array( '%s' ),
array( '%d' )
);
if ( ! empty( $members_result_update ) ) {
$member_details_decode = json_decode($member_details_encode, true);
$count_member_decode = count( $member_details_decode['member_image'] );
for ( $i = 0; $i < $count_member_decode; $i++ ) {
$m_image_name = $member_details_decode['member_image'][$i];
$profile_image_folder = "profile-images/";
$profile_image_path = trim( $profile_image_folder . basename( $m_image_name ) );
$profile_image_temp = $_FILES['member_image']['tmp_name'][$i];
$profile_image_ext = strtolower( end( explode( '.', $m_image_name ) ) );
if ( $profile_image_ext == "jpg" || $profile_image_ext == "png" || $profile_image_ext == "jpeg" || $profile_image_ext == "gif" ) {
move_uploaded_file( $profile_image_temp, $profile_image_path );
}
}
}
}
Every thing works well but when I select a new image in first field and submit the value to the database, it removes all other images of other fields from database...
And if I select image for other fields and submit the value to database it then creates new field with that value...
In simple terms, When I want to update any particular file field in the dynamic add / remove file field then that particular field should only be get updated and other fields should remain intact.
Pl Help...
I had this problem and i did it :(Example)
if ( empty( $options['index1_cardimg'] ) ) {$options['index1_cardimg'] = get_myoption_value('index1_cardimg');}
without this check (if (empty){}) all other fields will be reset .
just you need to fill them by last data (if they dont send) .
with a code like this:
if ( empty( $members_result_update ) ) {
// fill Other options with last value
}
Hi i've been trying to generate the following XML with PHP.
I've managed to generate it all except for the location section as it seems to treat it as another root and error out. Does anyone know the correct way to produce this?
<?xml version="1.0" encoding="UTF-8"?>
<classifieds xmlns="http://www.bdjjobs.com/ClassifiedJobFromRecruiterFeed">
<job>
<reference_id>20161114-72</reference_id>
<recruiter>Smiles R Us</recruiter>
<job_title>Denture Specialist</job_title>
<short_description><![CDATA[An exciting position in a dynamic dental practice]]></short_description>
<description><![CDATA[<p>Full description of post</p>]]></description>
<location>
<city>city</city>
<state>county</state>
<country>country</country>
</location>
<salary_description><![CDATA[Full Package]]></salary_description>
<organisations>Independent Dental Practice</organisations>
<job_type>Specialist Appointments</job_type>
<salary_band>£100,000 or more</salary_band>
<contract_type>Associate Permanent</contract_type>
<hours>Full time</hours>
<practice_type>Mixed (NHS/Private)</practice_type>
<start_date>2016-09-01</start_date>
<expiry_date>2016-10-30</expiry_date>
<application_email>apply_here#email.com</application_email>
</job>
</classifieds>
Any assistance would be greatly appreciated, thanks :)
Here is the code:
// Start Job Element
$job_element = $xml_document->createElement("job");
// Job ID
$rootreferencenumber = $xml_document->createElement("reference_id");
$rootreferencenumber->appendChild($xml_document->createCDATASection( get_the_ID() ));
$job_element->appendChild($rootreferencenumber);
// Recruiter
$recruiter = $xml_document->createElement("recruiter");
$recruiter->appendChild($xml_document->createCDATASection( "MBR Dental Recruitment" ));
$job_element->appendChild($recruiter);
// Job title
$title = $xml_document->createElement("title");
$title->appendChild($xml_document->createCDATASection( get_the_title() ) );
$job_element->appendChild($title);
// Job Description
$description = $xml_document->createElement("description");
$description->appendChild($xml_document->createCDATASection( ( strip_tags( str_replace( "</p>", "\n\n", get_the_content() ) ) ) ) );
$job_element->appendChild($description);
// City
$city = $xml_document->createElement("city");
$get_city = explode( ',', get_post_meta( get_the_ID(), 'geolocation_city', true ) );
$city->appendChild($xml_document->createCDATASection( $get_city[0] ) );
$job_element->appendChild($city);
// Region from Taxonomy
$region = $xml_document->createElement("region");
$categories = wp_get_post_terms( get_the_ID(), 'job_listing_region', array( "fields" => "names" ) );
if ( $categories && ! is_wp_error( $categories ) ) {
$region->appendChild( $xml_document->createCDATASection( implode( ',', $categories ) ) );
} else {
$region->appendChild( $xml_document->createCDATASection( '' ) );
}
$job_element->appendChild($region);
// Create Company Name
$company_name = $xml_document->createElement("organisations");
$company_name->appendChild($xml_document->createCDATASection('xx'));
$job_element->appendChild($company_name);
// Create Phone Number
$phone_number = $xml_document->createElement("phone_number");
$phone_number->appendChild($xml_document->createCDATASection('0000'));
$job_element->appendChild($phone_number);
// Job direct URL
$url = $xml_document->createElement("application_url");
$url->appendChild($xml_document->createCDATASection(get_permalink( get_the_ID() )));
$job_element->appendChild($url);
// Category
$phone_number = $xml_document->createElement("job_type");
$phone_number->appendChild($xml_document->createCDATASection('Job'));
$job_element->appendChild($phone_number);
// Subcategory
$region = $xml_document->createElement("subcategory");
$categories = wp_get_post_terms( get_the_ID(), 'job_listing_category', array( "fields" => "names" ) );
if ( $categories && ! is_wp_error( $categories ) ) {
$region->appendChild( $xml_document->createCDATASection( implode( ',', $categories ) ) );
} else {
$region->appendChild( $xml_document->createCDATASection( '' ) );
}
$job_element->appendChild($region);
// Job date based on todays date
$date = $xml_document->createElement("start_date");
$date->appendChild($xml_document->createCDATASection(date(Ymd) ));
$job_element->appendChild($date);
// Job date expire from original post date
$expiry_date = $xml_document->createElement("expiry_date");
$wpDate = (date(Ymd) );
$wpDate = new DateTime($wpDate);
$wpDate->add(new DateInterval('P14D')); // P14D means a period of 14 days
$wpDate = $wpDate->format('Ymd');
$expiry_date->appendChild($xml_document->createCDATASection( $wpDate ));
$job_element->appendChild($expiry_date);
// Create Application Email Address
$app_email = $xml_document->createElement("application_email");
$app_email->appendChild($xml_document->createCDATASection('xx#xx.com'));
$job_element->appendChild($app_email);
// End Job Element
$root->appendChild($job_element);
Ok so i was approaching this completely wrong..
I needed to append the child elements (City + Region) to the new $location element. Not to the original $job_element
here is the correct code:
// Start Job Element
$job_element = $xml_document->createElement("job");
// Job ID
$rootreferencenumber = $xml_document->createElement("reference_id");
$rootreferencenumber->appendChild($xml_document->createCDATASection( get_the_ID() ));
$job_element->appendChild($rootreferencenumber);
// Recruiter
$recruiter = $xml_document->createElement("recruiter");
$recruiter->appendChild($xml_document->createCDATASection( "xx" ));
$job_element->appendChild($recruiter);
// Job title
$title = $xml_document->createElement("title");
$title->appendChild($xml_document->createCDATASection( get_the_title() ) );
$job_element->appendChild($title);
// Job Description
$description = $xml_document->createElement("description");
$description->appendChild($xml_document->createCDATASection( ( strip_tags( str_replace( "</p>", "\n\n", get_the_content() ) ) ) ) );
$job_element->appendChild($description);
//Create Location Element
$location = $xml_document->createElement("location");
$job_element->appendChild($location);
// City
$city = $xml_document->createElement("city");
$get_city = explode( ',', get_post_meta( get_the_ID(), 'geolocation_city', true ) );
$city->appendChild($xml_document->createCDATASection( $get_city[0] ) );
$location->appendChild($city);
// Region from Taxonomy
$region = $xml_document->createElement("region");
$categories = wp_get_post_terms( get_the_ID(), 'job_listing_region', array( "fields" => "names" ) );
if ( $categories && ! is_wp_error( $categories ) ) {
$region->appendChild( $xml_document->createCDATASection( implode( ',', $categories ) ) );
} else {
$region->appendChild( $xml_document->createCDATASection( '' ) );
}
$location->appendChild($region);
// Country Code
$country = $xml_document->createElement("country");
$country->appendChild($xml_document->createCDATASection('UK'));
$location->appendChild($country);
// Create Company Name
$company_name = $xml_document->createElement("organisations");
$company_name->appendChild($xml_document->createCDATASection('xx'));
$job_element->appendChild($company_name);
// Create Phone Number
$phone_number = $xml_document->createElement("phone_number");
$phone_number->appendChild($xml_document->createCDATASection('xx'));
$job_element->appendChild($phone_number);
// Job direct URL
$url = $xml_document->createElement("application_url");
$url->appendChild($xml_document->createCDATASection(get_permalink( get_the_ID() )));
$job_element->appendChild($url);
// Category
$job_type = $xml_document->createElement("job_type");
$job_type->appendChild($xml_document->createCDATASection('Job'));
$job_element->appendChild($job_type);
// Subcategory
$region = $xml_document->createElement("subcategory");
$categories = wp_get_post_terms( get_the_ID(), 'job_listing_category', array( "fields" => "names" ) );
if ( $categories && ! is_wp_error( $categories ) ) {
$region->appendChild( $xml_document->createCDATASection( implode( ',', $categories ) ) );
} else {
$region->appendChild( $xml_document->createCDATASection( '' ) );
}
$job_element->appendChild($region);
// Job date based on todays date
$date = $xml_document->createElement("start_date");
$date->appendChild($xml_document->createCDATASection(date(Ymd) ));
$job_element->appendChild($date);
// Job date expire from original post date
$expiry_date = $xml_document->createElement("expiry_date");
$wpDate = (date(Ymd) );
$wpDate = new DateTime($wpDate);
$wpDate->add(new DateInterval('P14D')); // P14D means a period of 14 days
$wpDate = $wpDate->format('Ymd');
$expiry_date->appendChild($xml_document->createCDATASection( $wpDate ));
$job_element->appendChild($expiry_date);
// Create Application Email Address
$app_email = $xml_document->createElement("application_email");
$app_email->appendChild($xml_document->createCDATASection('x#xx.net'));
$job_element->appendChild($app_email);
// End Job Element
$root->appendChild($job_element);
$old = get_post_meta($post_id, 'figure_sugsubject_repeatable_fields', true);
$new = array();
$figuresugsubjectpositions = $_POST['figuresugsubjectposition'];
$figuresugsubjectworkplaces = $_POST['figuresugsubjectworkplace'];
$figuresugsubjectlocations = $_POST['figuresugsubjectlocation'];
$figuresugsubjectfroms = $_POST['figuresugsubjectfrom'];
$figuresugsubjectstatuss = $_POST['figuresugsubjectstatus'];
$count = count( $figuresugsubjectpositions );
for ( $i = 0; $i < $count; $i++ ) {
if ( $figuresugsubjectpositions[$i] != '' ) :
$new[$i]['figuresugsubjectposition'] = stripslashes( strip_tags( $figuresugsubjectpositions[$i] ) );
$new[$i]['figuresugsubjectworkplace'] = $figuresugsubjectworkplaces[$i];
$new[$i]['figuresugsubjectlocation'] = $figuresugsubjectlocations[$i];
$new[$i]['figuresugsubjectfrom'] = $figuresugsubjectfroms[$i];
$new[$i]['figuresugsubjectstatus'] = $figuresugsubjectstatuss[$i];
endif;
}
if ( !empty( $new ) && $new != $old )
update_post_meta( $post_id, 'figure_sugsubject_repeatable_fields', $new );
elseif ( empty($new) && $old )
delete_post_meta( $post_id, 'figure_sugsubject_repeatable_fields', $old );
I have a frontend form for post submission. I want the new entries in the form not to replace the old ones, instead I want it to be added. To replace update_post_meta with add_post_meta will not solve the problem as users will not be able to edit their old inputs.
Thank you.
I've got the following PHP code that I'm using to output a list of all custom taxonomy values, then group them into alphabetical order by first letter. This is working fine, except that the URL isn't being outputted. Anyone able to help?
<?php
$list = '';
$tags = get_terms( 'film-categories' );
$groups = array();
if( $tags && is_array( $tags ) ) {
foreach( $tags as $tag ) {
$first_letter = strtoupper( $tag->name[0] );
$groups[ $first_letter ][] = $tag;
}
if( !empty( $groups ) ) {
foreach( $groups as $letter => $tags ) {
$list .= '<div class="cat-group"><h3>' . apply_filters( 'the_title', $letter ) . '</h3>';
$list .= '<ul>';
foreach( $tags as $tag ) {
$url = esc_attr( get_tag_link( $tag->term_id ) );
$name = apply_filters( 'the_title', $tag->name );
$list .= '<li>' . $name . '</li>';
}
$list .= '</ul></div>';
}
}
} else $list .= '<p>Sorry, but no tags were found</p>';
echo $list;
?>
I'm afraid you've confused.
According to your second line - you're fetching terms of custom tax and not tags.
$tags = get_terms( 'film-categories' );
Therefore , any function related to tags won't work correctly.
In order to get the url of the term use the get_term_link() function.
Just replace the current line with:
$url = esc_attr( get_term_link( $tag ) );
Should work.