I have this super simple code to update a JetEngine Meta data field for a CPT called "Plans" after a post update:
add_action( 'save_post_plans', 'xb_update_display_fields2', 10, 3 );
function xb_update_display_fields2( $post_id, $post, $update ){
remove_action( 'save_post_plans', 'xb_update_display_fields2', 10 );
$id = $post->ID;
$postarr = array( 'ID' => $id, 'post_content' => 'Test content update');
wp_update_post( $postarr );
update_post_meta( $id, 'lifetime-pricing', 3688);
}
I've added the "Test content update" part just as a test and it works fine after a post update but the Meta data update doesn't work when I update a post.
It does however work when I create a new post. lifetime-pricing is a numeric, I've tried with text fields and same thing.
I've tried with the save_post hook instead of the save_post_plans hook and same result.
Hopefully somebody can help me figure it out. Many thanks! :)
Related
I want to make url like this in Yii1 http://example.com/customer-name. It would list jobs for the customer-name, this customer-name will be changing dynamically for example customer-name can be
customer-name=IBM or customer-name=abc-mn or customer-name=xyz
The urls will be something like this
http://example.com/IBM
http://example.com/abc-mn
http://example.com/xyz
I have tried many tutorials but when I a try nothing works for me. Also I followed the http://www.yiiframework.com/doc/guide/1.1/en/topics.url
You new to configure the main.php config properly and have your controller action ready.
private/protected/config/main.php
'urlManager'=>array(
//path is slash separated format aka www.url.com/controller/action/getparam/getvalue
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>true,
'rules'=>array(
//site is your controller, comapny is your action and the name is get variable actionCompany is waiting for.
'<name>' => 'site/company'
)),
private/protected/controllers/SiteController.php (alos make sure the actioname company is in accessRules if you user acceessControll filter).
public function actionCompany( $name )
{
/* your action code */
$this->render('test', array( 'test' => 'to_view' ) );
}
If this didn't help then you have to give us more of your code.
Today I've encountered error with php-code, it worked for six months, and now it falls
$listResponse = $youtube->search->listSearch(
'id,snippet',
array(
'channelId' => 'UCeP5_pUXbKpMlR-_mVQTCSg',
'maxResults'=>3,
'order'=>'date',
'type'=>'video',
'videoCategoryId'=>'UCeP5_pUXbKpMlR-_mVQTCSg.jNQXAC9IVRw'
)
);
I've checked it with "youtube try'it" service and get error http://take.ms/WXSBj
Please!! Help me! Need Assistance!)
UPDATE 1: This is API BUG: do you know how to get category videos via another method ?
and problem is only in parameter videoCategoryId
The reason is probably in video category id values,
I've get that values via method $youtube->channelSections->listChannelSections
It is popularVideos.
So, my code works without specifying them thanks to "order = date" parameter.
Suddenly the feed on our homepage has the - This device is no longer supported - video from YouTube. Everyone is seeing this no matter what device they are on, so we think it doesn't like something about the plugin now after YouTube changed and knew they would not be seen on certain devices and televisions: https://youtube.com/devicesupport
What is the fix for this? Are you pushing out an update to address this? Thanks.
https://wordpress.org/plugins/youtube-channel-gallery/
I would recommend taking a read through this thread in the support forum for the plugin:
https://wordpress.org/support/topic/getting-no-longer-supported-video-from-youtube
There are some different solutions, depending on whether you are using the widget or shortcode, but a few different approaches came up depending on what is easiest for you - personally, I favor this one:
open the file wp-content/plugins/youtube-channel-gallery.php
goto line 622 and paste this (directly under the foreach-line): if ($entry->title == 'https://youtube.com/devicesupport') { continue; }
let the plugin display 1 more video than before (maxitems)
What it does is: just throws away the "device support" video from the video feed. so there's one video less now, this is why you have to add 1 to the maxitems.
*Credit goes to Wordpress.org forums member "koem"
I had the same issue for the youtube videos and I fixed as follows:
After the installation of the youtube plugin in our site, we can see that the folder with the file name youtube-feeder.php
There is a function named "getFeedUrl" and this function is calling from the function
So the line is:
$dataURL ="To get the above URL please follow the below step";
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list
put the part as contentDetails and forUsername as [channel id] eg:Google
then execute then find the "uploads": "UUK8sQmJBp8GCxrOtXWBpyEA" from the list (ID will be different for your channel)
then go to the following:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.list
Then put the part as snippet and paste the copied uploads id in the playlistId then execute. you can see the result and you just copy the Request URL from the result.
Note: you need to register your application for API_KEY
developers.google.com/youtube/registering_an_application
Second:
You need to change the parsing section also:
OLD code:
$entries = array();
if($data && is_array($data['feed']['entry']))
{
foreach($data['feed']['entry'] as $vid)
{
$vid = $vid['media$group'];
$url = $vid['media$content'][0]['url'];
$url = substr($url, 0, stripos($url, '?'));
$entries[] = array(
'id' => $vid['yt$videoid']['$t'],
'url' => $url,
'title' => $vid['media$title']['$t'],
'date' => $vid['yt$uploaded']['$t'],
'content' => $vid['media$description']['$t']
);
}
}
New Modification:
$entries = array();
if($data && is_array($data['items']))
{
foreach($data['items'] as $vid)
{
//var_dump($data['items']);
$vid = $vid['snippet'];
$url = "https://www.youtube.com/watch?v="+$vid['resourceId']['videoId'];
//$url = substr($url, 0, stripos($url, '?'));
$entries[] = array(
'id' => $vid['resourceId']['videoId'],
'url' => $url,
'title' => $vid['title'],
'date' => $vid['publishedAt'],
'content' => $vid['description']
);
}
}
Then check it out, If its not coming the exact data, please comment the following line also.
`if(!$entries = $this->getCachedYoutubeData($id, $cache, $type, $orderby))`
Please write here if you have.
Youtube API 3 is very different from API 2. I just switched plugins - wpyoutubevideogallery.com - easy to setup and fully functional with youtube API 3. Also free.
Twitter Module is working finde with my Drupal 7 site. I wanted to make a tweek so that nodes that are not hidden get tweeted, I was able to do this by altering twitter_post_node_insert in twitter/twitter_post . All I did was add a new condition of !$node->hidden . It works great.
function twitter_post_node_insert($node) {
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post'])
&& !$node->hidden) { ......
My problem is that this code in the Twitter Module only gets called when I directly edit a node and save it. Now, I would like to have said code called also when I edit my node programmatically, where I save it with $node_wrapper->save(); . The twitter code won't get called. I've also tried with node_save($node); , instead of using my $node_wrapper. Nothing.
I also tried including the file twitter_post.module located in twitter/twitter_post, and then calling the function in charge of posting the tweet :
module_load_include('module', 'twitter', '../twitter/twitter_post/twitter_post');
twitter_post_node_update($node);
Nothing happens and no errors are shown. What I'd like is to know what Drupal 7 function gets called in its core when you edit a node through its interface and then save it. That way I can just put that function in the code where I edit my node programmatically so that the Twitter code will also get called. Or, does anyone have a better approach?
Thanks.
After looking into the Twitter module this is what I have done in order to have the nodes published programmatically.
I added the following function to twitter/twitter_post/twitter_post.module . It's a copy of the function function twitter_post_node_insert($node), found on the same file. I made a copy so that it would not print out the message of "tweet posted succesfully". That way I call the copied function from another place to post the tweet.
/**
* Function called from custom .module to insert tweets from "Editar Pesos" tab
*/
function twitter_post_node_custom_insert($node) {
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post']) && !$node->hidden ) {
module_load_include('inc', 'twitter');
$twitter_account = twitter_account_load($node->twitter['account']);
$replacements = array(
'!title' => truncate_utf8($node->title, 90, false, true),
'!url' => url('node/' . $node->nid, array('absolute' => TRUE, 'alias' => TRUE)),
'!url-alias' => url('node/' . $node->nid, array('absolute' => TRUE))
);
// Only generate the shortened URL if it's going to be used. No sense
// burning through TinyURLs without a good reason.
if (strstr($node->twitter['status'], '!tinyurl') !== FALSE) {
$replacements['!tinyurl'] = twitter_shorten_url(url('node/' . $node->nid,
array('absolute'=> TRUE)));
}
$status = strtr($node->twitter['status'], $replacements);
return twitter_set_status($twitter_account, $status);
}
}
And following is the "magic", which gets called whenever I want the node posted as a tweet.
function post_to_twitter($node){
module_load_include('module', 'twitter', '../twitter/twitter_post/twitter_post');
$twitter = array(
'account' => getTwitterUid(),
'post' => 'POST',
'status' => "!title !tinyurl"
);
$node->twitter = $twitter;
return twitter_post_node_custom_insert($node);
}
function getTwitterUid(){
return db_query("select twitter_uid from {twitter_account} where screen_name = :screen_name
limit 1", array(":screen_name" => 'YOUR_TwitterScreenName'))->fetchField();
}
Hope this can help anyone who was looking for the same thing as I.
I'm trying to use DbTableGateway to store my session information in a MySQL database--but my "sessions" table is remaining empty. It never contains any rows. Here's my code (more or less copy/pasted from here):
$dbAdapter = new Zend\Db\Adapter\Adapter(array(
'driver' => 'pdo_mysql',
'database' => 'db-name',
'username' => 'username',
'password' => 'password!'
));
$tableGateway = new \Zend\Db\TableGateway\TableGateway('session', $dbAdapter);
$saveHandler = new \Zend\Session\SaveHandler\DbTableGateway($tableGateway, new \Zend\Session\SaveHandler\DbTableGatewayOptions());
$manager = new \Zend\Session\SessionManager();
$manager->setSaveHandler($saveHandler);
$someContainer = new Container('SomeSessionNamespace');
$someContainer->aBitOfData = 'tasty morsel of data';
And here's a video demonstration of me using this code:
http://screencast.com/t/UDDUs6OZOib
As you can see in the video, session information is preserved between requests, but it's not being stored in the database.
I added breakpoints to every function in Zend\Session\SaveHandler\DbTableGateway, and the only one that's getting hit is in __constructor. So the constructor is getting called, but apparently it never gets used for anything else.
What am I missing?
I'm using Zend Framework 2.2.2 on PHP 5.3.
-Josh
I found some modules to do that if you need to implement this quickly
https://github.com/Nitecon/DBSessionStorage
https://github.com/gabriel403/G403SessionDb
To use your current code, please check:
options of ** DbTableGatewayOptions** (id, data, lifetime, etc..)
$options = new \Zend\Session\SaveHandler\DbTableGatewayOptions();
$options->setDataColumn('data');
$options->setIdColumn('id');
$options->setLifetimeColumn('lifetime');
$options->setNameColumn('name');
$options->setModifiedColumn('modified');
the start of you SessionManager $manager->start();
Check in application.config.php and make sure the Application module is at the top level
Also make sure that in
'vendor/composer/autoload_namespaces.php' and
'vendor/composer/autoload_static.php'
zend and zendxml library path added or not
eg : 'Zend' => array(vendorDir . '/ZF2/library'),
'ZendXml' => array(vendorDir . '/ZF2/library')