Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am building a theme and I need to call theme options But I do get errors like white screen and 500 internal server error when I call theme options here

In WP query (newbie in PHP)

 <?query_posts ('meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value=get_option(mytheme_value);');?>

Also in my front end form

// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title'    =>  $title,
'post_content'  =>  $description,
'post_category' =>  array($_POST['cat']),  // Usable for custom  taxonomies too
'tags_input'    =>  array($tags),
'post_status'   =>  'get_option(mytheme_status)',     

and how can I call a option in functions.php

share|improve this question
    
what errors are you getting? –  gteh Dec 20 '12 at 6:32
    
White screen and some times 500 internal server erroe –  vaibhav Dec 20 '12 at 6:33
    
"AND CAN I CALL A OPTION IN FUNCTIONS.PHP" ... Why are you screaming? And why did you add the php tag? Nearly every question is PHP related. Please rework your question. Thanks. –  kaiser Dec 20 '12 at 7:56
    
Oops that was a mistake. I didn't notice it as i had posted this question from my mobile –  vaibhav Dec 20 '12 at 8:06
add comment

2 Answers

up vote 5 down vote accepted

First, change your code into the following:

$value = get_option( 'mytheme_value' );
query_posts ( "meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value={$value}");

When you use single quotation marks, php isn't parsed in the string, and functions (like get_option) will never be called from within a string. Therefore, call the function get_option first, and put the value in a double quoted string (which parses variables during execution).

Then change your other code into the following:

// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title'    =>  $title,
'post_content'  =>  $description,
'post_category' =>  array($_POST['cat']),  // Usable for custom  taxonomies too
'tags_input'    =>  array($tags),
'post_status'   =>  get_option( 'mytheme_status' ),

When you want to call a function inside an array, using whatever it returnes as value, you don't need to put the function inside single quotes.

Furthermore, if you want to get option values in functions.php, you can simply use the following line:

$mytheme_status = get_option( 'mytheme_status' );

When you still encountering errors after these modifications, and you still get a blank screen, try to find out whats going wrong by looking in your error logs. On a linux environment, the default apache error log file location is /var/log/apache2/error.log or /var/log/httpd/error_log.

share|improve this answer
add comment

In both codes, the get_option function should be outside of the string, like this:

<?php 
$theme_value = get_option('mytheme_value');
query_posts ('meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value='.$theme_value);?>

and

$theme_status = get_option('mytheme_status');
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
    'post_title'    =>  $title,
    'post_content'  =>  $description,
    'post_category' =>  array($_POST['cat']),  // Usable for custom  taxonomies too
    'tags_input'    =>  array($tags),
    'post_status'   =>  $theme_status,

And why do you end this last code with a comma? You just put a part of the code? If not, you have to remove the comma and close the array.

Also, what are these variables mytheme_value and mytheme_status? Do they exist?

If you still have errors, you should write here the rest of the code.

share|improve this answer
    
They exists i had just used to make the question proper so all users can understand it –  vaibhav Dec 20 '12 at 8:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.