Why can't acces to instagram recent media? - instagram

I am working with instagram api, to get top media and recent media, i don't have problems calling top media, but 2 days ago i implemented this and called 3 last recent media to my page,
today like 1 hour ago i only could see 1 of three last media i called and now after 1 hour can't see any of them when i print the array who contains recent media it says its empty i don't know why.
Checking calls from my application graphic it doesn't show a big traffic, so i think it's not the problem because i can see top media.
<?php
include 'define.php';
function makeApiCall($endpoint, $type, $params)
{
$ch = curl_init();
if ('POST' == $type) {
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_POST, 1);
} elseif ('GET' == $type) {
curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$hashtag = 'sedapal';
$hashtagId = '17843308429009249';
$hashtagSearchEndpoingFormat = ENDPOINT_BASE . 'ig_hashtag_search?user_id={user-id}&q={hashtag-name}&fields=id,name';
$hashtagDataEndpointFormat = ENDPOINT_BASE . '{hashtag-id}?fields=id,name';
$hashtagTopMediaEndpointFormat = ENDPOINT_BASE . '{ig-hashtag-id}/top_media?user_id={user-id}&fields=id,caption,children,comments_count,like_count,media_type,media_url,permalink';
$hashtagRecentEndpointFormat = ENDPOINT_BASE . '{ig-hashtag-id}/recent_media?user_id={user-id}&fields=id,caption,children,comments_count,like_count,media_type,media_url,permalink';
$hashtagSearchEndpoint = ENDPOINT_BASE . 'ig_hashtag_search';
$hashtagSearchParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,name',
'q' => $hashtag,
'access_token' => $accessToken
);
$hashtagSearch = makeApiCall($hashtagSearchEndpoint, 'GET', $hashtagSearchParams);
/* To get hashtagID */
/* echo '<pre>';
print_r($hashtagSearch);
die(); */
$hashtagDataEndpoint = ENDPOINT_BASE . $hashtagId;
$hashtagDataParams = array(
'fields' => 'id,name',
'access_token' => $accessToken
);
$hashtagData = makeApiCall($hashtagDataEndpoint, 'GET', $hashtagDataParams);
$hashtagTopMediaEndpoint = ENDPOINT_BASE . $hashtagId . '/top_media';
$hashtagTopMediaParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,caption,children,comments_count,like_count,media_type,media_url,permalink',
'access_token' => $accessToken
);
$hashtagTopMedia = makeApiCall($hashtagTopMediaEndpoint, 'GET', $hashtagTopMediaParams);
$topPost = $hashtagTopMedia['data'][0];
$topPost1 = $hashtagTopMedia['data'][1];
$hashtagRecentEndpoint = ENDPOINT_BASE . $hashtagId . '/recent_media';
$hashtagRecentParams = array(
'user_id' => $instagramAccountId,
'fields' => 'id,caption,children,comments_count,like_count,media_type,media_url,permalink',
'access_token' => $accessToken
);
$hashtagRecent = makeApiCall($hashtagRecentEndpoint, 'GET', $hashtagRecentParams);
$recentPost = $hashtagRecent['data'][0];
/* $recentPost2 = $hashtagRecent['data'][1];
$recentPost3 = $hashtagRecent['data'][2]; */
?>
<p><?php echo json_encode($hashtagRecent['data']) ?></p>

That's because recent_media "Only returns media objects published within 24 hours of query execution", as said in the recent_media documentation.
The posts you couldn't see anymore were probably older than 24 hours the second time you fetched them.
top_posts will return posts no matter how old they are.
I struggled with this too and that was what happened to me.

Related

How to send customer renewal order to secondary email in Woocommerce subscription

I want to send the renewal order email to a secondary user email(which i have added in user-edit page using ACF).
I have tried many methods,woocommerce_subscription_payment_complete is also not working for me.
The following code i have tried:
add_action( 'woocommerce_order_status_completed', 'action_on_order_status_completed', 20, 2 );
function action_on_order_status_completed( $order_id, $order ){
$order = new WC_Order($order_id);
// Get the user ID from WC_Order methods
$user_id = $order->get_user_id(); // or $order->get_customer_id();
$secondary_recipient = get_field('secondary_email', 'user_'.$user_id );
$subscriptions_ids = wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => 'any' ) );
// We get all related subscriptions for this order
foreach( $subscriptions_ids as $subscription_id => $subscription_obj )
if($subscription_obj->order->id == $order_id) break; // Stop the loop
// $subscription_objc = wcs_get_subscription($subscription_id);
//$userid = $subscription_objc->get_user_id();
$wc_emails = WC()->mailer()->get_emails();
$wc_emails['WCS_Email_Processing_Renewal_Order']->recipient = $secondary_recipient;
$wc_emails['WCS_Email_Processing_Renewal_Order']->trigger($subscription_id);
// $to = $secondary_recipient;
// $subject = "hi";
// $body =$user_id."end".$order_id."hhh".$subscription_id;
// $headers = array('Content-Type: text/html; charset=UTF-8');
// //$headers[] = 'Cc: sarun#cloudspring.in';
// wp_mail( $to, $subject, $body, $headers );
}
FYI:Email is sending if i use the commented wp_mail function.
We can add a secondary email as the recipient, Try the below code tested and it worked.
add_filter( 'woocommerce_email_recipient_customer_completed_renewal_order', 'my_email_recipient_filter_function', 10, 2);
function my_email_recipient_filter_function( $recipient, $order ) {
$user_id = $order->get_user_id(); // or $order->get_customer_id();
$secondary_recipient = get_field('secondary_email', 'user_'.$user_id );
if(! empty($secondary_recipient)){
$recipient = $recipient . ', '. $secondary_recipient;
return $recipient;
}else {
return $recipient;
}
}

Instagram Profile Picture in Full-Resolution?

how do I get the profile picture of an instagram profile in full-res? (The old URL scheme stopped working today).
regex='profile_pic_url_hd":"([0-9a-zA-Z._-/:]*)",'
Is working for 320px pictures, but nothing else. The prefix to the 150x150 img is different, but the ID/ending of the url with jpg is the same.
Thanks
Okay guys I found a final solution:
Get the user_id of the account using this link https://www.instagram.com/{name}/?__a=1
Visit this JSON-API with the user_id above https://i.instagram.com/api/v1/users/{user_id}/info/
The full size profile picture link can be found in [hd_profile_pic_url_info][url]
Thats it! :)
[EDIT]
If step 1 doesn't work, my Php solution to get the user-id:
$name = "{username}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/$name/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($http=="200") {
$doc = new DOMDocument();
$doc->loadHTML($result);
$xpath = new DOMXPath($doc);
$js = $xpath->query('//body/script[#type="text/javascript"]')->item(0)->nodeValue;
$start = strpos($js, '{');
$end = strrpos($js, ';');
$json = substr($js, $start, $end - $start);
$data = json_decode($json, true);
$user_id = $data["entry_data"]["ProfilePage"][0]["graphql"]["user"]["id"];
}
I'm searching in the HTML document for user-id.
If you view the source html and run a simple find text search for logging_page_id, it will have profilePage_, then a number. That number is the user id.
e.g.:
logging_page_id":"profilePage_123456789
The user id is: 123456789

How to traverse a graph with ArangoDB and PHP

ArangoDB provides documents and edges as a low level way to produce graphs.
Let's say we have set up a graph with some vertices and edges.
The graph represents the relationship between the vertices.
v2 is a child of v1
v3 is a child of v2
v4 is a child of v3
v5 is a child of v1
v6 is a child of v5
We want to be able to query:
The path from v4 to v1
All descendants of v1
The children of v1
All ancestors of v4
The parents of v4
How to do that in PHP?
The way to do this is by querying ArangoDB with its AQL (ArangoDB Query language).
There are a few commands for working with graphs in AQL.
With PHP, we have to create a statement with the query and execute that.
The attached code uses the TRAVERSAL function in order to provide the results to the queries mentioned in the question.
This script sets up a document and an edge collection, fills it with vertices and connecting edges, and finally does the querying in order to provide the results.
It can be executed as is and will print out all the results.
<?php
namespace triagens\ArangoDb;
// use this and change it to the path to autoload.php of the arangodb-php client if you're using the client standalone...
// require __DIR__ . '/../vendor/triagens/ArangoDb/autoload.php';
// ...or use this and change it to the path to autoload.php in the vendor directory if you're using Composer/Packagist
require __DIR__ . '/../vendor/autoload.php';
// This function will provide us with our pre-configured connection options.
function getConnectionOptions()
{
$traceFunc = function ($type, $data) {
print "TRACE FOR " . $type . PHP_EOL;
};
return array(
ConnectionOptions::OPTION_ENDPOINT => 'tcp://localhost:8529/',
// endpoint to connect to
ConnectionOptions::OPTION_CONNECTION => 'Close',
// can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections)
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
// use basic authorization
/*
ConnectionOptions::OPTION_AUTH_USER => '', // user for basic authorization
ConnectionOptions::OPTION_AUTH_PASSWD => '', // password for basic authorization
ConnectionOptions::OPTION_PORT => 8529, // port to connect to (deprecated, should use endpoint instead)
ConnectionOptions::OPTION_HOST => "localhost", // host to connect to (deprecated, should use endpoint instead)
*/
ConnectionOptions::OPTION_TIMEOUT => 5,
// timeout in seconds
//ConnectionOptions::OPTION_TRACE => $traceFunc, // tracer function, can be used for debugging
ConnectionOptions::OPTION_CREATE => false,
// do not create unknown collections automatically
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST,
// last update wins
);
}
// This function tries to create vertices and edges for the example
function setupVerticesAndEdges($connection, $vertexCollection, $edgeCollection)
{
echo "We are creating 6 vertices...<br> ";
//create example documents for the vertices
$nameV1 = 'v1';
$documentV1 = Document::createFromArray(
array('name' => $nameV1, '_key' => $nameV1)
);
$nameV2 = 'v2';
$documentV2 = Document::createFromArray(
array('name' => $nameV2, '_key' => $nameV2)
);
$nameV3 = 'v3';
$documentV3 = Document::createFromArray(
array('name' => $nameV3, '_key' => $nameV3)
);
$nameV4 = 'v4';
$documentV4 = Document::createFromArray(
array('name' => $nameV4, '_key' => $nameV4)
);
$nameV5 = 'v5';
$documentV5 = Document::createFromArray(
array('name' => $nameV5, '_key' => $nameV5)
);
$nameV6 = 'v6';
$documentV6 = Document::createFromArray(
array('name' => $nameV6, '_key' => $nameV6)
);
echo "We are creating 5 edges...<br> ";
//create example documents for the edges
$nameE1 = 'e1';
$documentE1 = Edge::createFromArray(
array('name' => $nameE1, 'label' => 'child_of')
);
$nameE2 = 'e2';
$documentE2 = Edge::createFromArray(
array('name' => $nameE2, 'label' => 'child_of')
);
$nameE3 = 'e3';
$documentE3 = Edge::createFromArray(
array('name' => $nameE3, 'label' => 'child_of')
);
$nameE4 = 'e4';
$documentE4 = Edge::createFromArray(
array('name' => $nameE4, 'label' => 'child_of')
);
$nameE5 = 'e5';
$documentE5 = Edge::createFromArray(
array('name' => $nameE5, 'label' => 'child_of')
);
// Get instances of the vertice- and edgehandlers
$documentHandler = new DocumentHandler($connection);
$edgeHandler = new EdgeHandler($connection);
// Save the vertices
try {
// query the given $collectionId by example using the previously declared $exampleDocument array
$result['v'][] = $documentHandler->save($vertexCollection, $documentV1);
$result['v'][] = $documentHandler->save($vertexCollection, $documentV2);
$result['v'][] = $documentHandler->save($vertexCollection, $documentV3);
$result['v'][] = $documentHandler->save($vertexCollection, $documentV4);
$result['v'][] = $documentHandler->save($vertexCollection, $documentV5);
$result['v'][] = $documentHandler->save($vertexCollection, $documentV6);
} catch (Exception $e) {
// any other error
echo ('An error occured. Exception: ' . $e);
}
// Save the edges
try {
echo "$nameV2 is a child of $nameV1<br> ";
$result['e'][] = $edgeHandler->saveEdge(
$edgeCollection,
$vertexCollection . '/' . $nameV2,
$vertexCollection . '/' . $nameV1,
$documentE1,
$options = array()
);
echo "$nameV3 is a child of $nameV2<br> ";
$result['e'][] = $edgeHandler->saveEdge(
$edgeCollection,
$vertexCollection . '/' . $nameV3,
$vertexCollection . '/' . $nameV2,
$documentE2,
$options = array()
);
echo "$nameV4 is a child of $nameV3<br> ";
$result['e'][] = $edgeHandler->saveEdge(
$edgeCollection,
$vertexCollection . '/' . $nameV4,
$vertexCollection . '/' . $nameV3,
$documentE3,
$options = array()
);
echo "$nameV5 is a child of $nameV1<br> ";
$result['e'][] = $edgeHandler->saveEdge(
$edgeCollection,
$vertexCollection . '/' . $nameV5,
$vertexCollection . '/' . $nameV1,
$documentE4,
$options = array()
);
echo "$nameV6 is a child of $nameV5<br> ";
$result['e'][] = $edgeHandler->saveEdge(
$edgeCollection,
$vertexCollection . '/' . $nameV6,
$vertexCollection . '/' . $nameV5,
$documentE5,
$options = array()
);
echo "<font style='font-family: monospace;'>";
echo "$nameV1<br> ";
echo "+ $nameV2<br> ";
echo "| + $nameV3<br> ";
echo "| | + $nameV4<br> ";
echo "+ $nameV5<br> ";
echo "+ $nameV5<br> ";
echo "| + $nameV6<br> ";
echo "</font>";
// return the result;
return $result;
} catch (Exception $e) {
// any other error
echo ('An error occured. Exception: ' . $e);
}
}
// helper function that takes the connection and the query to execute.
function doAQLQuery($connection, $query)
{
// query through AQL
$statement = new \triagens\ArangoDb\Statement($connection, array(
"query" => '',
"count" => true,
"batchSize" => 1000,
"_sanitize" => true,
));
$statement->setQuery($query);
$cursor = $statement->execute();
$result = $cursor->getAll();
return $result;
}
// AQL query example functions
// Function that gets all paths from vertex v4 to v1
function getPathFromV4ToV1($connection)
{
$query = 'FOR p IN PATHS(vertices_20130301_01, edges_20130301_01, "outbound")
FILTER p.source._id == "vertices_20130301_01/v4" && p.destination._id == "vertices_20130301_01/v1"
RETURN p';
$result = doAQLQuery($connection, $query);
return $result;
}
// Function that gets the paths to all descendants of v1
function getPathToAllDescendantsOfV1($connection)
{
$query = 'FOR p IN TRAVERSAL(vertices_20130301_01, edges_20130301_01, "vertices_20130301_01/v1", "inbound", {
strategy: "depthfirst",
minDepth:1,
paths: true,
followEdges: [ { label: "child_of" } ]
})
RETURN p
';
$result = doAQLQuery($connection, $query);
return $result;
}
// Function that gets the paths to all children of v1
function getPathToChildrenOfV1($connection)
{
$query = 'FOR p IN TRAVERSAL(vertices_20130301_01, edges_20130301_01, "vertices_20130301_01/v1", "inbound", {
strategy: "depthfirst",
maxDepth: 1,
minDepth:1,
paths: true,
followEdges: [ { label: "child_of" } ]
})
RETURN p
';
$result = doAQLQuery($connection, $query);
return $result;
}
// Function that gets the paths to all parents of v4
function getPathToParentsOfV4($connection)
{
$query = 'FOR p IN TRAVERSAL(vertices_20130301_01, edges_20130301_01, "vertices_20130301_01/v4", "outbound", {
strategy: "depthfirst",
maxDepth: 1,
minDepth:1,
paths: true,
followEdges: [ { label: "child_of" } ]
})
RETURN p
';
$result = doAQLQuery($connection, $query);
return $result;
}
// Function that gets the paths to all ancestor of v4
function getPathToAllAncestorsOfV4($connection)
{
$query = 'FOR p IN TRAVERSAL(vertices_20130301_01, edges_20130301_01, "vertices_20130301_01/v4", "outbound", {
strategy: "depthfirst",
minDepth:1,
paths: true,
followEdges: [ { label: "child_of" } ]
})
RETURN p
';
$result = doAQLQuery($connection, $query);
return $result;
}
// Function that drops collections given
function dropCollections($connection, $collections)
{
// register a collection handler to work with the 'users' collection
$collectionHandler = new CollectionHandler($connection);
echo "dropping collections...";
try {
foreach ($collections as $collection) {
$collectionHandler->drop($collection);
}
echo "dropped.<br>";
} catch (Exception $e) {
die ('Could not drop collection. Exception: ' . $e . '<br>');
}
}
// *********************************************************************************************************************
// Start example code
// register the connection to ArangoDB
$connection = new Connection(getConnectionOptions());
// register a collection handler to work with the 'users' collection
$collectionHandler = new CollectionHandler($connection);
// assign the collection names...
$vertexCollection = 'vertices_20130301_01';
$edgeCollection = 'edges_20130301_01';
// finally drop the collections...
// remark this line if you want to drop the collections by hand.
dropCollections($connection, array($vertexCollection, $edgeCollection));
// create the vertices and edges collections...
// remark those lines if you want to create the collection by hand.
echo "creating the '$vertexCollection' vertex collection...";
try {
$collection = new Collection();
$collection->setName($vertexCollection);
$collectionHandler->create($collection);
echo "created.<br>";
} catch (Exception $e) {
echo ('Could not create collection. Exception: ' . $e . '<br>');
}
echo "creating the '$edgeCollection' edge collection...";
try {
$collection = new Collection();
$collection->setName($edgeCollection);
$collection->setType(3);
$collectionHandler->create($collection);
echo "created.<br>";
} catch (Exception $e) {
echo ('Could not create collection. Exception: ' . $e . '<br>');
}
// setup our vertices and edges....
echo "trying to setup our vertices and edges... <br>";
$result = setupVerticesAndEdges($connection, $vertexCollection, $edgeCollection);
// AQL Examples
// get the path from vertex v4 to v1
$result = getPathFromV4ToV1($connection);
echo "<br>*****************************************<br>";
echo "get all paths from vertex v4 to v1<br>";
echo "<br>*****************************************<br>";
var_dump($result);
// get the paths to all descendants of v1
$result = getPathToAllDescendantsOfV1($connection);
echo "<br>*****************************************<br>";
echo "get the paths to all descendants of v1<br>";
echo "<br>*****************************************<br>";
var_dump($result);
//get the paths to all children of v1
$result = getPathToChildrenOfV1($connection);
echo "<br>*****************************************<br>";
echo "get the paths to all children of v1<br>";
echo "<br>*****************************************<br>";
var_dump($result);
// get the paths to all ancestors of v4
$result = getPathToAllAncestorsOfV4($connection);
echo "<br>*****************************************<br>";
echo "get the paths to all ancestors of v4<br>";
echo "<br>*****************************************<br>";
var_dump($result);
//get all paths to all parents of v4
$result = getPathToParentsOfV4($connection);
echo "<br>*****************************************<br>";
echo "get all paths to all parents of v4<br>";
echo "<br>*****************************************<br>";
var_dump($result);

How to link custom results in Drupal

My first time here an a newbee in Drupal and programming .
So I have a problem I need to some help with.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$resultarray = array();
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$resultarray[$nodeobj->nid] = $nodeobj->title;
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$rows = array();
$i = 0;
foreach($resultarray as $nid => $title) {
$i++;
$rows[] = array('data' =>
array(
$i,
$title,
),
);
}
$output = theme('table', $header, $rows);
print theme("page", $output);
}
It's driving me crazy , i dint put all of the search code but it takes taxonomy tags from the database ( you type in textbox that has autocomplete, '$searchstring' ) and date ( you choose a time line like one day , yesterday ect. , '$datefrom').
For example reasons lets say it looks like this example when you click search.
I can't post my one pictures but I just gives me the titles ( like above but the are not listed) that I cannot click to lead me to the content.
But I wont it to look like result that is like content ( story ) so you have a clickable Title and some description , like this click to see example
where it says lorem ipsum and that text belowe.
If it is hard to make like in the picture can someone show me just how to make( like in the first picture) the results that are non clickable titles into clickable links that lead me to the content.
To get linked titles you need to use the l() function.
looking at the code you provided, I am not entirely sure how you are getting any results since you save the titles in $resultArray but use $rows when rendering the table.
Unless, $rows is specified somewhere else, $resultarray[$nodeobj->nid] = $nodeobj->title; should become $rows[$nodeobj->nid] = $nodeobj->title;
To make it match your table header, you need to add another 'cell' for the number column
$rows[$nodeobj->nid] = array(
$count++,
l($nodeobj->title, 'node/'.$nodeobj->nid)
);
To provide the excerpt too, you need to join the node_revisions table and get either the body or teaser column, then add it to your rows like this:
$rows[$nodeobj->nid] = array(
$count++,
'<h2>'. l($nodeobj->title, 'node/'.$nodeobj->nid) .'</h2>'. $nodeobj->teaser
);
assuming you get the teaser.
EDIT
the previous answer still holds. You can also simplify the code a bit by processing $rows straight in the $noderesults loop.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$rows = array();
$count = 0;
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n "
."INNER JOIN {term_node} tn ON tn.nid = n.nid "
."WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$rows[] = array(
++$count,
l($nodeobj->title, 'node/'. $nodeobj->title)
);
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$output = theme('table', $header, $rows);
print theme("page", $output);
}
-OR-
move it all in one query (note: I did not get a chance to test this, but I usually get it right the first time):
function query_results($searchstring, $datefrom) {
$rows = array();
$count = 0;
$results = db_query("SELECT n.nid, n.title
FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid IN (SELECT tid FROM {term_data} WHERE LOWER(name) = '%s')", strtolower($searchstring));
while ($nodeobj = db_fetch_object($results)) {
$rows[] = array(
++$count,
l($nodeobj->title, 'node/'. $nodeobj->title)
);
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$output = theme('table', $header, $rows);
print theme("page", $output);
}

drupal form api checkboxes

I am using drupal form api and using checkboxes. I am getting problem in default checked values with it. following is the code snippet...
$result = db_query("SELECT nid, filepath FROM {content_type_brand}, {files} WHERE content_type_brand.field_brand_image_fid
= files.fid");
$items = array();
while ($r = db_fetch_array($result)) {
array_push($items, $r);
}
$options = array();
foreach( $items as $i ) {
$imagePath = base_path().$i['filepath'];
$options[$i['nid']] = '<img src="'.$imagePath.'"></img>';
}
$form['favorite_brands'] = array (
'#type' => 'fieldset',
'#title' => t('Favorite Brands'),
//'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['favorite_brands']['brands_options']
= array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $options_checked,// $options_checked is an array similar to $options but having elements which need to be checked by default...
'#multicolumn' => array('width' => 3)
);
but values are not checked by default... can anyone help what I am missing??
Thanks
Your $options_checked array should not be in the same format as your $options array. Your $options array contains nid => img tag pairs. Your $options_checked array should simply contain the nid values of the options that should be checked by default:
$options_checked = array(8,17);

Resources