0

I realise this is perhaps more of a php question rather than WP-specific, but figure/hope it's relevant.

I annotate my code probably more than is needed (because I know relatively little about this, and it helps me to better understand).

I'm wondering how best to deal with these two instances...

In:

$query->set( 'post__not_in', array(
41,     // page title
43,     // /page title
) );

BBEdit syntax highlight is ok, and the code works.

Whereas in:

wp_list_pages( array(
'exclude'               => '
41, // page title
43, // page title
',
) );

BBEdit syntax highlight is incorrect, but the code works.

Is it ok (reliable) to include such comments - and is there a better alternative?

1 Answer 1

1

No, it's definitely not okay to comment your code this way. It changes the string, and even though WordPress might strip the incorrect characters and yield the correct pages (it wouldn't if your "comments" contained comma's or numbers), it is incredibly unstable. Instead, if you do want to comment them, I would suggest storing them as an array, commenting that in the way you described, and implode-ing it with a comma:

$exclude_ids = array(
    41, // First page title
    43, // Second page title
);

wp_list_pages( array(
    'exclude' => implode( ',', $exclude_ids ),
) );
2
  • Thanks for your advice. Appreciated. Having had a quick look at that 'implode' link I shall study it more so I can better understand. Commented Jun 30, 2017 at 13:57
  • Quick follow-up, sorry for my confusion. Having modified my use of wp_list_pages accordingly, I'm unclear about the '$query->set' first part of my question - does that also need to be changed in similar manner? Commented Jul 2, 2017 at 5:30

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.