0

I am working on a website that alternates section depending on the ID, I created this code but noticed one of my parameters is not working correctly

$fb_prac = array('34565', '34565', '1212', '1192', '1219', '1180', '1234','1186', '1221'); 
if (get_the_ID() != ('34565' or '34565' or '1212' or '1192' or '1219' or '1180' or '1234' or '1221')) {
    include 'facebook.html';}
    else {
        if (get_the_ID() == '1186') {
         include 'facebook-1186.html';}else{
    echo do_shortcode('[facebook_card]');}}

The ID pointing to 1186 is ok and the else echoing the shot code is ok BUT the array wit the IDs pointing to facebook.html do not load. Is there something wrong with my syntax? Any help is appreciated

5
  • this is not javascript Commented Dec 17, 2019 at 20:40
  • $fb_prac? Are you writing php in JS? Commented Dec 17, 2019 at 20:42
  • This looks like Wordpress. (do_shortcode is a Wordpress function, AFAIK). Regardless, this definitely isn't JS. Commented Dec 17, 2019 at 20:42
  • im sorry I meant to put PHP! Commented Dec 17, 2019 at 20:49
  • That if line with these or conditions does not look like valid PHP Commented Dec 18, 2019 at 11:35

2 Answers 2

4

Did you try to use the in_array function?

if (in_array(get_the_ID(), $fb_prac)) {
    include 'facebook.html';
}

https://www.php.net/manual/en/function.in-array.php

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

7 Comments

I did and when I do that it overwrites the else for 1186 and the shortcode else, it just puts the facebook.html globally
Just compare that ID before this one.
this doesn't work, the pages that display the shortcode and the 1186 page all show the facebook.html
@triby not following what exactly do you mean?
@triby Thank you for your help! I removed the 1186 from the top array and now everything is showing where it should! thanks!
|
1

I'm reading the logic like this, if the id matches 1186 include facebook-1186.html, if the id is NOT in your array $fb_prac, then include facebook.html. Else do the shortcode.

<?php

$fb_prac = array('34565', '34565', '1212', '1192', '1219', '1180', '1234','1186', '1221'); 
$id = get_the_ID();

if ($id == '1186') {
    include 'facebook-1186.html';
}
elseif (!in_array($id, $fb_prac)) {
    include 'facebook.html';
}
else {
    echo do_shortcode('[facebook_card]');
}

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.