Using custom php to connect to database blocks wp from accessing galery pictures

I'm using simplepie to get a bunch of rss feeds and post them in a database from which I later show themon my pag

I'm using simplepie to get a bunch of rss feeds and post them in a database from which I later show them on my page. I've added a custom php file with a shortcode to do this.

    // Connect to DB
$sDbHost = 'localhost';
$sDbName = 'database_name';
$sDbUser = 'somethin';
$sDbPwd = 'somethin';
$Conn = mysqli_connect($sDbHost, $sDbUser, $sDbPwd);
mysqli_select_db($Conn, $sDbName);

if ($Conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$get_from_table = "SELECT title, link FROM rss_news";
$result = $Conn->query($get_from_table);
mysqli_close($Conn);

The database I'm connecting to is a new one I created specifically to do this function, I also created a new user to connect to this db.

This all works, I mange to get the posts into the db and pull them from it to show on the page. The issue is that once this is active it blocks the "add file" option within the classic wordpress editor from accessing the media library.

Is there something I'm doing wrong here? Is there a better way to connect to the db to avoid blocking other connections?

I'm using simplepie to get a bunch of rss feeds and post them in a database from which I later show them on my page. I've added a custom php file with a shortcode to do this.

    // Connect to DB
$sDbHost = 'localhost';
$sDbName = 'database_name';
$sDbUser = 'somethin';
$sDbPwd = 'somethin';
$Conn = mysqli_connect($sDbHost, $sDbUser, $sDbPwd);
mysqli_select_db($Conn, $sDbName);

if ($Conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$get_from_table = "SELECT title, link FROM rss_news";
$result = $Conn->query($get_from_table);
mysqli_close($Conn);

The database I'm connecting to is a new one I created specifically to do this function, I also created a new user to connect to this db.

This all works, I mange to get the posts into the db and pull them from it to show on the page. The issue is that once this is active it blocks the "add file" option within the classic wordpress editor from accessing the media library.

Is there something I'm doing wrong here? Is there a better way to connect to the db to avoid blocking other connections?

Share Improve this question edited Oct 26, 2019 at 17:39 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Oct 26, 2019 at 16:52 AdiliciousAdilicious 1193 bronze badges 2
  • Hello! You said you added a custom PHP file and provided the source, but can you be more specific about how this file is called? Is this a file in a plugin? Does it get loaded by WordPress or do you visit the file directly in the browser? – Tom J Nowell Commented Oct 26, 2019 at 18:04
  • The file gets added into wordpress via shortcode, I added the php in my theme folder and added the shortcode into my functions.php file. The file gets loaded by wordpress every time a user opens up the test page I made. Its only opened up when I'm testing and the script opens and closes the db connection so I'm not sure why the media library is not loaded – Adilicious Commented Oct 26, 2019 at 19:35
Add a comment  | 

1 Answer 1

Reset to default 0

The solution to this was dumb but it works. I just had to refresh the post article page once and I could access the media library again.

I guess the script would take preference over the media gallery? And then when I refreshed the page it would take preference again and could connect. I'm just guessing here, but if anybody else has this issue this is the simple fix.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745050351a4608348.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信