0

I am creating a wordpress shortcode [ADD_POT ID='X'], which is able to get the ID value, in purpose to execute a function.

Unfortunately, there is an error within the third line of my code. Someone can give me a hand please ? Thank you.

function ADD_POT($atts) {
    $ID = shortcode_atts(array( 'ID' => TRUE), $atts) ;
    $pot_ID = $ID['ID'] ;
    include dirname(__FILE__) . '/../../../wp-config.php' ;
    include dirname(__FILE__) . '/../../../wp-content/plugins/Study-Tool/core/login.php' ;
    $pot_selection = "SELECT question_ID FROM questions WHERE pot_ID='$pot_ID'" ;
    $pot_result = mysqli_query ($connect,$pot_selection) ;
    foreach ($pot_result as $pot_ID) {
        $question_ID = $pot_ID['question_ID'] ;
        ADD_Q($question_ID) ;
    }
}
8
  • For have some fun Commented May 20, 2017 at 22:18
  • The real reason is because i need login for in purpose to use a complexe script, hide in ADD_Q Commented May 20, 2017 at 22:36
  • Ah ok, I didn't know that. Thank you. Commented May 20, 2017 at 22:39
  • I put the shortcode into my post, but nothing appear :/ Commented May 20, 2017 at 22:40
  • 1
    Very bad idea to use relative link and include once again the wp-config.php. If you want to query and use sql query you only need to add global $wpdb; at the top of the function, and use plugins_url() (if your running this in a plugin) and get_stylesheet_uri() (for a theme) to include any file. Commented May 21, 2017 at 6:56

2 Answers 2

1

Value in this line means default value your ID field have if user has not supplied a value.

$ID = shortcode_atts(array( 'ID' => TRUE), $atts) ;

You need to enclose values in '' in this line for example something like

$ID = shortcode_atts(array( 'ID' => ''), $atts) ;

if you want to have blank as default value. For any other value use the value but in quotes. If user gives a value in input then that value will be used instead of blanks or default value you give here.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer Esha, but the real problem is, my function don't use the value given by the user in a post like [ADD_POT ID='X'], instead of the defaut value placed in the array :/
Someone else have an idea please ?
1

I solve the problem. It was because I used uppercase instead of lowercase in my wordpress balise.

[POT_ID **id**=4]

function ADD_POT($atts) {
    $ID = shortcode_atts(array( '**id**' => '1'), $atts);
    $pot_ID = $ID['**id**'];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.