• Hi,

    I followed the instructions in this topic to get the ID of the associated post.

    But I get this error:

    Fatal error: Uncaught Error: Class 'MslsOptions' not found in D:\Ampps\www\europass\wp-content\themes\demo-theme\page.php on line 21

    Here my code:

    $linked_post = '';
                
    if ( get_locale() == 'de_DE') {      
      $mslsOption = new MslsOptions();
      $linked_post = $mslsOption->en_EN;
    }

    What am I doing wrong?

    Thanks for the support,

    Simone

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Dennis Ploetner

    (@realloc)

    The classes are now namespaced but I’m not sure if that language code works (is it en_GB or en_US?):

    $linked_post = '';           
    if ( get_locale() == 'de_DE') {      
      $mslsOption = new \lloc\Msls\MslsOptions();
      $linked_post = $mslsOption->en_GB;
    }
    Thread Starter Simone Montanari

    (@semikola)

    Hi Dennis,

    thank you. I also corrected the language code (en_US in my case).

    I tested the code but it works only with ->get_arr();

    $mslsOption = new \lloc\Msls\MslsOptions();
    $linked_post = $mslsOption->en_US;
    $linked_posts = $mslsOption->get_arr();
                
    var_dump( $linked_post );
    var_dump( $linked_posts );

    For the $linked_post I always get null.

    D:\Ampps\www\ep\wp-content\themes\demo-theme\page.php:25:null

    D:\Ampps\www\ep\wp-content\themes\demo-theme\page.php.php:26:
    array (size=7)
      'admin_language' => string 'en_US' (length=5)
      'display' => int 1
      'only_with_translation' => string '1' (length=1)
      'description' => string 'English' (length=7)
      'before_output' => string 'Switch language:' (length=16)
      'content_priority' => string '10' (length=2)
      'reference_user' => string '1' (length=1)

    But I’m also starting to think I misunderstood what this code does.

    Because I don’t understand how can I retrieve the ID of the connected pages from the array information.

    Basically in my page Test DE I want to show some information from the connected page Test EN (in my case some files). So I need to be able to get the ID of the page.

    Thanks a lot for your help,

    Simone

    Plugin Author Dennis Ploetner

    (@realloc)

    OK, I get the problem. I wasn’t focussed to a particular thing here. MslsOptions works much better with its factory where it decides how to call the specialized subclasses. It’s quite simple:

    $mslsOption = \lloc\Msls\MslsOptions::create();
    echo $mslsOption->en_US;
    echo $mslsOption->get_arr()->en_US;

    As you can see in my example, calling the magic getter or the get_arr method should return the same result.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get ID associated post/page’ is closed to new replies.