Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:02:05+00:00 2026-05-27T02:02:05+00:00

So I have been working with WordPress 3.x and trying to build a custom

  • 0

So I have been working with WordPress 3.x and trying to build a custom display of content already stored in the WP MySQL db. I need to parse the WP post content itself for the mp3 URL in each so I can reuse it elsewhere in my code. There is a built-in function in WordPress called get_the_content() which grabs the post content data for use in my code.

I think I have reduced my code to literally 2 lines (I am trying to be as efficient as possible as this code all appears within a while loop) plus the echo statement to display the data captured in the array created by xpath. Problem seems that I keep getting an PHP Fatal error: Call to a member function xpath() on a non-object and the echo call returns no results. The first error shows on the shortcode [be-linked-title-info] and then again with the MP3 URL from the href.

This makes me think the post content is “dirty”. Amazon Cloud inserts a “+” for every space when files are uploaded and I cannot count on the filenames to be void of spaces as I have a team of people uploading content, so I want to be able to provide for fact that some might upload files with names that include spaces (that are subsequently converted to + symbols)

As mentioned, this error occurs with the shortcode as well as the href I am after, which could be b/c of the use of special characters? All I am after here is the MP3 URl in the href and nothing more. How can I clean this data so it parses properly (if that in fact is the issue)? Or maybe eliminate everything being parsed except the tag and its attribute? Can someone provide me some advice on what I am doing incorrectly please?

This is an example of what every post looks like in terms of format & contents (this is exactly what is returned by the get_the_content() function):

<img class="myclass" title="mytitle" src="http://www.mydomain.com/myfolder/mypic.jpg" alt="myalt" width="552" height="414" />

[be-linked-title-info]

<a title="mytitle" href="https://s3.amazonaws.com/myfolder/published/RJD2+-+SEVEN+LIGHT+YEARS+(INSTRUMENTAL).mp3">Song Name and Artist</a>

The written plain text post entry describing this music track goes here and says blah blah blah

This is the code I am using that returns the error:

$xml  = simplexml_load_string(get_the_content());
$list = $xml->xpath("//a[contains(@href,'mp3')]/@href");

And later on I want to use this to return the URL captured from the href:

<?php $list[0]; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:02:06+00:00Added an answer on May 27, 2026 at 2:02 am

    The content obviously is not well-formed XML at all times. Try this method instead.

    // before the loop
    $doc   = new DOMDocument();
    $doc->strictErrorChecking = FALSE;
    
    $xpath = new DOMXpath($doc);
    
    // in the loop
    $success = $doc->loadHTML(get_the_content());
    if ($success === FALSE) {
      // error handling
    } else {
      $hrefs = $xpath->query("//a[contains(@href,'mp3')]/@href");
      foreach ($hrefs as $href) {
        // whatever
      }
    }
    

    To make this more efficient, simply concatenate all the article bodies before you build a DOMDocument from them. This way you’d have the document creation/destruction and XPath query penalty only once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wordpress site that i've been working on that has some pages
In an effort to learn more about php and mysql, I have been working
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working with a string[] array in C# that gets returned from
We have been working with CVS for years, and frequently find it useful to
I have been working on some legacy C++ code that uses variable length structures
I have been working with relational databases for sometime, but it only recently occurred
I have been working as a native C++ programmer for last few years. Now
I have been working with Struts for some time, but for a project I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.