Post to remote WordPress site with custom taxonomy - php

I'm using this code to push data to a custom post type of a remote website:
$api_response = wp_remote_post( 'https://example.com/wp-json/wp/v2/clothing_line', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'admin:5mMcJGUGNFYq9PxU5P0ad0Np' )
),
'body' => array(
'title' => 'Pink Shirt',
'status' => 'publish',
'post_type' => 'clothes',
'categories' => 2,
'slug' => 'pink-shirt',
'meta' => array('amount' => '12.50', 'style' => 'petite', 'size' => 'small', 'gender' => 'ladies', 'author' => 1)
)
));
...and it works fine except for one issue.
'categories' => 2 will probably work fine for regular categories, but I have a custom taxonomy for it called 'clothing_line_cats'.
I need the post that is created on the remote site to have the category for the 'clothing_line_cats' taxonomy.
I tried adding this...
'taxonomy' => 'clothing_line_cats'
...but that did not work.
I can't find any documentation for achieving this.

Feel kind of stupid I didn't realise this before.
Change this...
'categories' => 2
...to this...
'clothing_line_cats' => 2

Related

How to automatically edit page configuration and add a template from extension controller?

I am writing an Extbase Extension that automatically creates pages.
So far I have managed to add the pages, and they show up in the page tree. I have also got their page ids saved in variables.
$data = array(
'pages' => array(
'NEW_1' => array(
'pid' => '-1',
'title' => 'Page1',
),
'NEW_2' => array(
'pid' => 'NEW_1',
'title' => 'Page2',
),
'NEW_3' => array(
'pid' => 'NEW_1',
'title' => 'Page3',
),
'NEW_4' => array(
'pid' => 'NEW_1',
'title' => 'Page4',
),
)
);
$tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
$tce->stripslashes_values = 0;
$dataHandler->reverseOrder = 0;
$tce->start($data, []);
$tce->process_datamap();
\TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
$tce->clear_cacheCmd('pages');
$Page1id=$tce->substNEWwithIDs['NEW_1'];
$Page2id=$tce->substNEWwithIDs['NEW_2'];
$Page3id=$tce->substNEWwithIDs['NEW_3'];
$Page4id=$tce->substNEWwithIDs['NEW_4'];
Now I want to automatically add a Fluid-Template to these pages but I can't figure out how to do that without manually adding one in the backend. Does someone know how to do that?
Thank you in advance for your help.
As fluid templates are not assigned to pages immediately you need to set a layout which selects a template. You have multiple fields in a pages record. The most common fields probably are backend_layout and backend_layout_next_level. You also could use the field pagelayout but I prefer backend_layout as it has a nice inheritance mode, where you could except single pages.
Solutions could be found in the web or here on StackOverflow.
If your fluid template is selected with one of these fields you could set this field like any other field while creating the new records.
$data = array(
'pages' => array(
'NEW_1' => array(
'pid' => '-1',
'title' => 'Page1',
'backend_layout' => 'SpecialPageLayout',
),
'NEW_2' => array(
'pid' => 'NEW_1',
'title' => 'Page2',
'backend_layout' => 'SpecialPageLayout',
),
:

Prestashop custom module friendly url

I developed a custom module for Prestashop, and I have some issues regarding the friendly url parameters retrieval. If I disable the friendly url, everything works as supposed, but whenever I try with friendly url it doesn't work
So, the problem is the following:. I have a friendly url link just like the one below:
domain.com/22-flower-delivery-Hong+Kong.html
and the other link:
domain.com/22-flower-delivery-Hong+Kong-Sai+Kung.html
The first link gets a country page and the other one is showing a city inside that country.
The route in Prestashop is done like below:
$my_link = array(
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => '{id_country:-}flower-delivery{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'setCountry' => array('regexp' => '[0-9]+', 'param' => 'setCountry'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
'city' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*', 'param' => 'city'),
'module_action' => array('regexp' => '[\w]+', 'param' => 'module_action')
),
'params' => array(
'fc' => 'module',
'module' => 'vpages'
)
)
);
The main issue is that this works if the country or the city has a single word as name, but if there are 2 words (Hong Kong, New Zeeland, etc) then it will crash. A am using urlencode() and decode just to be sure that everything is passed ok but still with no luck.
Could someone help sort it out?

SugarCRM On-Demand Convert TextField to DropDown

A similar question was posted here before but it only applied to an On-Site SugarCRM instance (it was also a long time ago).
In my case I would like to change the "Billing Country" field from 'TextField' to 'DropDdown' on an On-Demand instance where I don't have access to the config files. How can I do this?
So far I have tried different PHP files using the Module Loader but it's not working either.
Please find my PHP script below:
<?php
$manifest = array(
'acceptable_sugar_flavors' => array('CE', 'PRO', 'CORP', 'ENT', 'ULT'),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
0 => '6\\.5\\.(.*?)',
1 => '6\\.7\\.(.*?)',
2 => '7\\.2\\.(.*?)',
3 => '7\\.2\\.(.*?)\\.(.*?)',
4 => '7\\.5\\.(.*?)\\.(.*?)',
5 => '7\\.6\\.(.*?)\\.(.*?)'
),
),
'name' => 'Textfield to Dropdown',
'description' => 'Converting Billing Country textfield to Dropdown Field',
'author' => 'myname',
'icon' => '',
'is_uninstallable' => true,
'published_date' => '2015-01-09 19:00:00',
'type' => 'module',
'version' => '1.0',
);
$dictionary['Account']['fields']['billing_address_country']['type'] = 'enum';
$dictionary['Account']['fields']['billing_address_country']['ext1'] = 'countries_dom';
The module loads fine but there's no change after a Quick Repair. I have tried with the following variables, as well:
$dictionary['Account']['fields']['billing_address_country']['isDropDown']=yes;
and...
$dictionary['Account']['fields']['billing_address_country']['Options']='countries_dom';
Can anyone tell me what I am doing wrong? I'd appreciate any help or guidance you have. Please advise.
Cheers,
H
P.S. I am using SugarCRM On-Demand Version 7.6.1
You need to create the manifest.php file and have that point to the file(s) you want to copy/upload for customization:
manifest.php:
<?php
$manifest = array(
'built_in_version' => '7.6.1.0',
'acceptable_sugar_versions' =>
array(
0 => '',
),
'acceptable_sugar_flavors' =>
array(
0 => 'PRO',
1 => 'CORP',
2 => 'ENT',
3 => 'ULT',
),
'readme' => '',
'key' => 'SO',
'author' => 'Eric',
'description' => 'Convert Accounts Billing Country TextField to Enum',
'icon' => '',
'is_uninstallable' => true,
'name' => 'TextFieldToDropdownPkg',
'published_date' => '2016-01-10 03:01:01',
'type' => 'module',
'version' => 1452378413,
'remove_tables' => 'prompt',
);
$installdefs = array(
'id' => 'TextFieldToDropdownPkg',
'copy' => array(
0 => array(
'from' => '<basepath>/custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php',
'to' => 'custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php',
),
),
);
Then create:
custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php
<?php
$dictionary['Account']['fields']['billing_address_country']['comments']='Country for primary address';
$dictionary['Account']['fields']['billing_address_country']['group']='primary_address';
$dictionary['Account']['fields']['billing_address_country']['options']='countries_dom';
$dictionary['Account']['fields']['billing_address_country']['type']='enum';
ZIP those files up and use Module Loader.

How to add new fields to user profile in Drupal 7 programmatically

I want to develop a module that add fields to user profile in drupal 7, like phone number and CV ...
and I don't know how to do that (using Database or using fields API)
pls help me.
Any clear tutorials will be appreciated.
Try to follow the following code
$myField_name = "NEW_FIELD_NAME";
if(!field_info_field($myField_name)) // check if the field already exists.
{
$field = array(
'field_name' => $myField_name,
'type' => 'text',
);
field_create_field($field);
$field_instance = array(
'field_name' => $myField_name,
'entity_type' => 'user', // change this to 'node' to add attach the field to a node
'bundle' => 'user', // if chosen 'node', type here the machine name of the content type. e.g. 'page'
'label' => t('Field Label'),
'description' => t(''),
'widget' => array(
'type' => 'text_textfield',
'weight' => 10,
),
'formatter' => array(
'label' => t('field formatter label'),
'format' => 'text_default'
),
'settings' => array(
)
);
field_create_instance($field_instance);
Hope this works... Muhammad.

How do I save custom node types in Drupal 7

I've created a custom node type in Drupal 7, using the hook_node_info method in the install file:
// declare the new node type
function foo_node_info ( ) {
return array(
'foo' => array(
'name' => t('Foo entry'),
'base' => 'node_content',
'description' => t('For use to store foo entries.'),
));
} // END function foo_node_info
and I'm trying to save that type in the module file using the following code:
// INSERT the stuff
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'Title, blah blah blah',
'url' => 'url here, just pretend',
'body' => '<p>test</p>',
)));
My issue, is that the url, and body fields aren't saving. Any idea what I'm doing wrong?
So, after a ton of digging, it turns out that the way I was entering the custom fields in the node_save was wrong. The node_save needs to look like the following:
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'the title',
'url' => array(
'und' => array(array(
'summary' => '',
'value' => 'url value',
'format' => 2,
))),
'body' => array(
'und' => array(array(
'summary' => '',
'value' => 'the body goes here',
'format' => 2,
))),
)));
Notice that for the custom fields, the array structure has to match what was previously going on with CCK (pretty much exactly). The first key in the array describing the field value is the language for the content.
I've used 'und' here only because that's what I saw going into the database when entering the data through a form.

Categories