I'm trying to work out what the option value is in get_permalink(get_option('jr_dashboard_page_id') I'm trying to follow this convention but cant work where it comes from - dashboard is the post-name in the DB what the rest of it means or how its works I cant figure out...
Any help would be great..
The Options API stores key-value pairs. For example, add_option( 'key', 'value' ); could be used. In that case, get_option( 'key' ); would return value.
So at some point a plugin or the themes that you use defined jr_dashboard_page_id to be something. Perhaps via a meta box or something like that. There is not enough information in this question to say exactly what "key" you need. It's like saying, I have an associative array $array['key'] what key should I use? We simply can't know because we don't know how array looks and we don't know what kind of value you expect.
Related
So I am trying to get custom post values in WP. The thing is I can have multiple custom fields value. So I don't want to hard code in the code. What I am thinking of doing is providing the a prefix in the key value something like
abc_email
abc_website
So I want to use this function
get_post_meta
or some other to get all the key,value pair that starts with abc. That way I can just add values on the back end and don't have to update my code. One way would be to get all the meta data using above function and then loop over it and filter. But is there any other way where I can send in the pattern I am looking for?
Thanks
You could directly query the database for a posts entries containing the prefix (relevant table etc here https://wordpress.stackexchange.com/questions/104434/where-are-custom-field-values-stored-in-the-database )
but this is more complex, still involves a loop and doesn't provide you with anything you could do using WP and PHP. If you want to cater for unknowns you will have to loop or interogate an index etc.
I may be missing something in your question but this seems straight forward:
You are trying to avoid this scenario:
process_field($abc_known1);
process_field($abc_known2);
// continually edit code for new entries e.g.:
process_field($abc_NEW1);
Something like this will handle later additions without modification.
// get array of ALL cust fields for post
$all_cust_fields = get_post_meta( get_queried_object_id());
foreach ($all_cust_fields as $key => $value) {
// some function for determing if $value starts with "abc_"
// if so either:
// add to an "abc" array for later use/processing
// or take action in this loop e.g.
process_field($value);
}
I am not sure whether you are talking about keys or values prefixed "abc_" but the same principle applies.
you should write code like this,
$email_meta = get_post_meta( 'your_post_id', 'abc_email', true );
$website_meta = get_post_meta( 'your_post_id', 'abc_website', true );
Or
you can follow these links,
example
example
Hope this will help you.
I'm just a little desperate.
I installed the RSS Display extension.
http://typo3.org/extensions/repository/view/rss_display
Everything works fine, but I have just a little understanding problem.
I pull myself with fluid the Author for the current feed.
<feed:item.get value="author"/>
Than i look whats inside.
<f:debug><feed:item.get value="author"/></f:debug>
Thats the result.
SimplePie_Author prototype object
name => 'Name Name' (12 chars)
link => NULL
email => NULL
So what i need it's to get the name of the author.
Unfortunately i am not able to get the value.
I am really new in Fluid, Typo3.
Hopefully someone can help me.
One way to do this, is to create a fluid variable author and assign the author object to it. Then you can access the name using {author.name}.
To create a variable, you could use the ViewHelper <f:alias>, like this:
<f:alias map="{author: '{feed:item.get(value: \'author\')}'}">
{author.name}
</f:alias>
Another way would be to use the extension "vhs", which provides many tools for use with fluid. One of these tools is the ViewHelper <v:variable.set>, which could be used like this:
<v:variable.set name="author" value="{feed:item.get(value: 'author\'}"/>
{author.name}
This has the advantage that you don't need to use the variable within the tags of the ViewHelper.
There are other ways to reach the same goal, without defining variables, but this seems to be the easiest one to me.
I am running into an issues with dump() in Twig.
I am not able to completely dump the values of the object that I am returning to my twig template. My object, as defined below, is built up of a product object, qty key/val, OnOrder key/val and avgUnitCost key/val.
I AM able to use dump(qty), dump(OnOrder), dump(avgUnitCost) and see the values of these.
I AM NOT able to use dump() on product to see the key/val of the product object. All I get is a white page of death.
I have read elsewhere on stack that it is a memory issue in the php.ini file. This does not seem to fix the issue, I set mine 1024M and it still times out and gives me the white screen.
I have also read this guys article on the same issue: http://hectorpinol.com/twig-debug-in-symfony-2/ ... He thinks it is a "bidirectional association problem".
In any case, here is the code that I am using to pass the object and render my twig template...
return $this->render('TestBundle:Event:view.html.twig', array(
'heading' => 'View Product',
'product' => $product,
'qty' => $qty,
'OnOrder' => $OnOrder,
'avgUnitCost' => $avgUnitCost,
));
Here is the guts of my question:
How can one effectively use twig to access the elements of an object, whether it be dump or some other method. I need to be able to see all of the elements in the object so that I can place them on the page as I need.
Thanks so much for your help!!!
Check LadybugBundle. You can dump everything.
Try adding a break point in twig_var_dump:
/vendor/twig/twig/lib/Twig/Extension/Debug.php (at the bottom)
Then you can use the functionality of your debugger...
Look at this answer: https://stackoverflow.com/a/29302069/4102223
It is my approach to solve this problem, only few lines must to be changed in one place (it is easier because no need to include new bundles and read its documentation).
In Smarty, I know you can declare a string:
{$somevar|default:'some string'}
or even an array:
{$somevar|default:array('someval')}
How do you/Is it possible to set an associative array as a default value? as this doesn't seem to work:
{$somevar|default:array('default'=>array('subkey'=>'subval'))}
I just tried:
{$somevar|default:array('key'=>'val')}
It's the '=>' smarty doesn't like
I know its probably not the solution you're looking for, but you can always just use the {php} feature. However, I will try a few things and see if I can work the format out.
Just out of interest, why are you trying to do this in the tpl file and not in the calling PHP script?
Edit
From takeing a read, it doesn't seem like it is possible. However, there is a "set" plugin which allows it, see here (bottom example).
I know that one way is to have a table in database with all the states and then you would read it in your form. Is there any easier way in your opinion guys ?
I feel bad asking for something like this since it is so elementary however I would suppose something as simple like this would already be implemented in Drupal.
No need to hit the database. Build yourself a function that returns an array of the states.
$form['state'] = array(
'#type' => 'select',
'#options' => mymodule_states_list(),
'#title' => t('State'),
);
function mymodule_states_list() {
return array(
'AL' => 'Alabama',
'AK' => 'Alaska',
...
'WY' => 'Wyoming',
);
}
If you're building the form using Drupal's FormAPI you could just include the array of states in your module code since the names and abbreviations shouldn't be changing any time soon.
If you're trying to keep your code clean, you could save an array of states as a Drupal variable using variable_set() and then retrieve it using variable_get(). You really shouldn't need to bother with the database for that kind of thing.
That is one way to do it, sure. You can store a list of states as a variable, and call it.
$options = variable_get('mymodule_us_states', 0);
So long as it's an array. You could also have an internal function that returns the states.
Or store it in a flat file and read it in. Eg
Flat file =
$us_states_options = array(
'AL' => 'Alabama',
'AK' => 'Alaska',
//...etc
)
Function:
include_once(drupal_get_path('module', 'module_name') .'/us_states.inc');
All pretty ugly, but you at least can edit that file independently, and may work well if you have a larger list. Theres a million ways you could have the list included - using exec, fgetcsv/file, etc....
But I think ceejayoz solution is the nicest. I'd probably spin out those sorts of utility functions into a seperate include to keep it clean myself.
The Country codes API module also provides a Regions codes API module which include US states. With this module, you can get an array suitable for a Form API select element by calling regions_api_iso2_get_options_array('US').
Just remembered this question as I was experimenting with the Geonames module. Among tons of other features, Geonames includes the function "geonames_us_states()" which returns an array of U.S. states keyed by the states' two letter code.