WORDPRESS Database How to return meta value from database? - sql

I have in database this meta_key fw:ext:mm:io:primefeed and this meta_value a:5:{s:4:"type";s:6:"column";s:3:"row";a:0:{}s:6:"column";a:1:{s:14:"item_thumbnail";a:2:{s:13:"attachment_id";s:2:"11";s:3:"url";s:49:"//primefeed.loc/wp-content/uploads/2020/01/01.jpg";}}s:4:"item";a:0:{}s:7:"default";a:0:{}}
How to return this meta value (link) //primefeed.loc/wp-content/uploads/2020/01/01.jpg ?

That's a PHP serialized array. You can see the structure using
print_r( unserialize( $value ) );
e.g. repl.it demo
Inside WordPress, you can do
$meta_value = get_post_meta($post_id, "fw:ext:mm:io:primefeed", true);
$url = $meta_value["column"]["item_thumbnail"]["url"];
where get_post_meta does both the database fetch and unserialize.

Related

Get value from customer_entity_varchar - Magento

I created a customer attribute in backend magento, but I want to show this attribute to the user so that he can alter its value in the frontend. My input field is being displayed in the frontend, but the value is not there. I am not able to get this value. I found that the value that I need to display is in the apscustomer_entity_varchar table and the column is called 'value'. How can I get that value from that table? I was trying this:
$collection = Mage::getModel('eav/entity_attribute')->getCollection();
foreach ($collection as $data) {
return $data;
}
but it was not working, so I used SQL code and it worked. However I know that's not a nice way to do that in Magento. What I did was something like:
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT * FROM `apscustomer_entity_varchar ` WHERE `entity_id`='$id'";
$rows = $connection->fetchAll($sql);
How can I get the value column from my apscustomer_entity_varchar table in the magento way, using the getModel?
You need to retrieve the customer of the session and then you can get the attribute you want :
Mage::getSingleton('customer/session')->getData('attributeName');
Mage::getSingleton('customer/session')->getAttributeName(); //Magic getter
Where attributeName is the name of the attribute you want to get the value.
I found out how to do that :D
It's actually very simple. Even if this is a custom customer attribute (created in Magento admin panel), I need to get the attribute not using the 'eav/entity_attribute' model, but using the 'customer/customer' model. So I just need to do that:
$customer_data = Mage::getModel('customer/customer')->load($customer_id)->getData();
echo $customer_data['attributeThatYouWant'];
If you are not sure what is the name of your attribute you can look at Magento Admin Panel under Customer/Manage-Attributes, or you can use that after getting the model:
var_dump($customer_data);
Now you are able to get the name of all customer attributes.

how to use mysql query in yii framework

I am new to yii framework using yii 1.1.14 First of all I didnt understand it. My target is to insert, select, update and delete data from database . Its very confusing for me.please give me some example .
Some examples
1.Insert query in YII2
$connection = Yii::$app->db;
$connection->createCommand()->insert('tbl_name', [
'column1' => Yii::$app->request->post('column1'),
'column2' => Yii::$app->request->post('column2'),
])->execute();
2.Update query
Yii::$app->db->createCommand()->update('tbl_name', [
'column1' => Yii::$app->request->post('column1'),
'column2' => Yii::$app->request->post('column2'),
],
'where_id ="'.$where.'" ')->execute();
I recommended you to use Gii, and use it to generate a Model of table.
For example, table: user(columns: id,name), Model: User.
You can insert or update data like the following:
$user = new User(); // Insert
// $user = User::find()->where(['id'=>'1'])->one(); // Update
$user->name = "Insert data";
$user->save();
See also http://www.yiiframework.com/doc-2.0/guide-start-gii.html
For the queries you can use Active Record and for CRUD you can use Gii

MailChimp API Get Subscribers ammount

I have been looking at the mailchimp api, and am wondering how to display the live ammount of subscribers to a list, is this possible? And is it possible to have this counter LIVE? I.e as users join, the number increases in real time?
EDIT:
I have been getting used to the API slightly...
after using Drewm's mailchimp php wrapper its starting to make more sense...
I have so far
// This is to tell WordPress our file requires Drewm/MailChimp.php.
require_once( 'src/Drewm/MailChimp.php' );
// This is for namespacing since Drew used that.
use \Drewm;
// Your Mailchimp API Key
$api = 'APIKEY';
$id = 'LISTID';
// Initializing the $MailChimp object
$MailChimp = new \Drewm\MailChimp($api);
$member_info = $MailChimp->call('lists/members', array(
'apikey' => $api,
'id' => $id // your mailchimp list id here
)
);
But not sure how to display these values, it's currently just saying 'array' when I echo $member_info, this maybe completly because of my ignorance in PHP. Any advice to s
I know this may be old, but maybe this will help someone else looking for this. Latest versions of API and PHP Files.
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp($api_key);
$data = $MailChimp->get('lists');
print_r($data);// view output
$total_members = $data['lists'][0]['stats']['member_count'];
$list_id = $data['lists'][0]['id'];
$data['lists'][0] = First list. If you have more, then it would be like $data['lists'][1] ect...
And to get a list of members from a list:
$data = $MailChimp->get("lists/$list_id/members");
print_r($data['members']);// view output
foreach($data['members'] as $member){
$email = $member['email_address'];
$added = date('Y/m/d',strtotime($member['timestamp_opt']));
// I use reverse dates for sorting in a *datatable* so it properly sorts by date
}
You can view the print_r output to get what you want to get.

Is there any way to make a ZF2 database adapter return column values in the appropriate data type?

Is there any way to make a ZF2 database adapter return column values in the appropriate data type, or does it always return data as strings?
Something like this (where $statement is a Zend\Db\Adapter\Driver\Pdo\Statement):
$rows = $statement->execute();
foreach ($rows as $row) {
$price = $row['price'];
}
$price is always a string, even though price is defined to be a float in the database.
Also, even if the answer is that MySQL/PostgreSQL/SQLite database adapters always return strings, would the answer be different for a different kind of database adapter?

Update specific field on SOLR index

I want to using solr for search on articles
I have 3 table:
Group (id , group name)
ArticleBase (id, groupId, some other field)
Article(id, articleBaseId, title, date, ...)
in solr schema.xml file i just define all article field that mixed with ArticleBase table (for use one index on solr) like this: (id, articleBaseId, groupId, ...)
problem: Admin want to change group (ArticleBase), therefore i must update (or replace) all indexed article in solr. right ? can i update groupId only in solr index ?
have any solution ?
Note:Article table contains more than 200 million article, and i using solr for index only (not store any field data except article id)
Solr does not support updating individual fields yet, but there is a JIRA issue about this (almost 3 years old as of this writing).
Until this is implemented, you have to update the whole document.
UPDATE: as of Solr 4+ this is implemented, here's the documentation.
Please refer to this document about the "Partial Documents Update" Feature in Solr 4.0
Solr 4.0 is now final and production-ready.
This feature makes it possible to update fields and even adding values to multiValued fields.
Mauricio was right with his answer back in 2010, but this is the way things are today.
SolrPHP doesn't provide any method to update a specific field in Solr.
However, you can make a Curl call in PHP to update a specific field:
<?php
// Update array
$update = array(
'id' => $docId,
$solrFieldName => array(
'set' => $solrFieldValue
)
);
$update = json_encode(array($update));
// Create curl resource and URL
$ch = curl_init('http://'.SOLR_HOSTNAME.':'.SOLR_PORT.'/'.SOLR_COLLECTION.'/update?commit=true');
// Set Login/Password auth (if required)
curl_setopt($ch, CURLOPT_USERPWD, SOLR_LOGIN.':'.SOLR_PASSWORD);
// Set POST fields
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $update);
// Return transfert
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set type of data sent
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Get response result
$output = json_decode(curl_exec($ch));
// Get response code
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close Curl resource
curl_close($ch);
if ($responseCode == 200)
{
echo 'SOLR: Updated successfully field '.$solrFieldName.' for id:'.$docId.' (query time: '.$output->responseHeader->QTime.'ms).';
}
else
{
echo ('SOLR: Can\'t update field '.$solrFieldName.' for id:'.$docId.', response ('.$responseCode.') is: '.print_r($output,true));
}
I use this code to update in JSON, you can also provide data in XML.
My Solution was something as below:
$client = new SolrClient($options);
$query = new SolrQuery();
// Find old Document
$query->setQuery('id:5458');
$query->setStart(0);
$query->setRows(1);
$query_response = $client->query($query);
// I had to set the parsemode to PARSE_SOLR_DOC
$query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC);
$response = $query_response->getResponse();
$doc = new SolrInputDocument();
// used the getInputDocument() to get the old document from the query
$doc = $response->response->docs[0]->getInputDocument();
if ($response->response->numFound) {
$second_doc = new SolrInputDocument();
$second_doc->addField('cat', "category123");
// Notice I removed the second parameter from the merge()
$second_doc->merge($doc);
$updateResponse = $client->addDocument($second_doc);
$client->commit();
}
You can refer to this documentation for Partial Updates. You can make an update either by replacing it or adding more values to that particular field although (like a list), it's not required in your case
Solr supports different types of Update Operations.
The set of update operations supported by Solr.
'add' - add a new value or values to an existing Solr document field, or add a new field and value(s).
'set' - change the value or values in an existing Solr document field.
'remove' - remove all occurrences of the value or values from an existing Solr document field.
Here is an example of how to do a partial update via Solr’s Java client, SolrJ
// create the SolrJ client
HttpSolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr");
// for clould there is CloudSolrClient api
// create the document
SolrInputDocument solrDocument = new SolrInputDocument();
solrDocument.addField("id","12345");
Map<String,Object> solrUpdates = new HashMap<>(1);
solrUpdates.put("address","Pune");
solrDocument.addField("cat", solrUpdates);
solrClient.add( solrDocument );
solrClient.close();