Wordpress loop inside of function = fatal error - php

I have my Wordpress blog on blog.mysite.com, and a totally different site (built in my framework) at www.mysite.com.
I know if the blog and another site are on the same server, and have correct permissions, I can use the following to "syndicate" my blogs to the non-blog site with:
define('WP_USE_THEMES', false);
require('/var/www/vhosts/mysite/subdomains/blog/httpdocs/wp-config.php');
query_posts('showposts=5');
...and then run a loop on the page.
The problem is that since my non-blog site is a framework, everything except for my front controller lives in a function - and this is creating the following error for me:
Fatal error: Call to undefined method
stdClass::set_prefix()
(btw, I'm fairly certain the fact that this code is called within a function that is causing the error...when I put the code on the front controller (not in function), the error disappears)
I would REALLY like to have recent blog listings on my non-blog site to spruce it up. Any ideas on how to do this?

Well I guess you forgot to write
global $wpdb
inside the function

Related

Error: Call to undefined function get_meta() in functions.php

I have inherited a custom wordpress theme and am doing a few changes to it (all cosmetics of changing city names, etc) , but at the bottom of a post I get the error : "Fatal error: Call to undefined function get_meta()"
In my functions.php I have this:
function bardetails(){
$web = get_meta('web');
$email = get_meta('email');
//...
}
I have a Java background but am new to php and wordpress. I dont see anywhere else this function is called, but must be tied to a post.
Have looked and can find a lot of problems about "get_post_meta()" and "meta()" but nothing about this. It also seems to be working on the other site the theme is on. I used FTP to pull over everything and all the other parts of the site seem to work fine. Looked at the database for something that could help with no luck, and also have tried to find if this is some kind of library, as the intention of the function is clear and thats to grab the website/email of the post.
So is this just a straight custom function? And if so were should it be defined in a php/wordpress setup?
It was due to a plugin that was not installed. "More Fields" By Henrik Melin, Kal Ström is a seemingly defunct plugin that was needed that allows you to use "get_meta()". For now, I just copied over the plugin but seems like I need to find an alternative going forward.

How to configure Vimeo-Service-module in Silverstripe

Forgive me for my English
I am new in PHP. And I'm building a site using Silverstripe and trying to configure Vimeo-Service-module. I'd follow the steps from this link
https://github.com/r0nn1ef/Silverstripe-Vimeo-Service-module
I did everything that mentions in the article. And created a page in admin panel of VimeoGallery page type and set the parameters on Videos tab to grab the videos for display.
After created page, I visited my and clicked on video menu but then all I see is no videos returned. It is showing blank page and no any error messages.
Is that I've done anything wrong. Please guide me...
Thanks in advance.
OK, I think I see the issue here. You are calling VimeoService::setAPIKey() however accessing the method like that is deprecated in the new version (the 2.0 branch - I was incorrect in my comment when I mentioned master) of the module.
The module instead uses the Site Config in the CMS to set the API key and a few other settings.
Now just remove VimeoService::setAPIKey() from your _config.php file, run /dev/build and set the API key through the CMS.
EDIT
On line 142 of VimeoGalleryPage.php, there is a function called flushCache. Replace the code in that function with the following:
public function flushCache($persistent = true) {
parent::flushCache($persistent);
unset($this->_cachedVideos);
}
Basically, the code in the 2.0 branch for this function does not correctly extend the same named function in SiteTree.

Fatal error caused by get_theme_mod()

I've been using the WordPress Customize.php functionality to allows users to customize my theme via the admin Customizer. It's been working fine offline in WAMP, but when I uploaded the theme to the testing server I received this message:
Fatal error: Can't use function return value in write context in [my url]/functions.php on line 181
The line it links to is a reference to get_theme_mod(), and in particular:
$page_data = get_page(get_theme_mod('page'));
Do I have to register the 'theme mods' in functions or something?
Right, I've found my issue - and another one has arose that I'm looking into...
For those that read this after searching the web having suffered the same problem, the reason I was receiving this error was because above this I was testing the get_theme_mod with an empty() function. Which, does not work as get_theme_mod is not a variable.
if(!empty(get_theme_mod('page'))){
$page_data = get_page(get_theme_mod('page'));
}

Including plugin files into main plugin file properly

I've been having this issue for a while but keep just working around it an thought I'd finally get it solved.
I'm trying to include files into my main plugin document (the one that has the plugin title and version in it) like this:
define('SBT_PLUGIN_URL', plugin_dir_url(__FILE__));
include(SBT_PLUGIN_URL . 'competition_table.php');
inside the competition_table.php is an add_shortcode(); function that needs to run, in order for the shortcode to be registered with wordpress:
function add_table() {
//Run code here
}
add_shortcode('competition_table', 'add_table');
When I run the code on the site the link resolves properly, including the correct file, however I get this Fatal Error:
Call to undefined function add_shortcode()
However if I add exactly the same code that is in the competition_table.php into my main plugin document then the code runs perfectly.
So basically, my question is, why is Wordpress not recognizing it's own function and how can I include the file to make the code run properly?
Thanks in advance
You have to develop with WP_DEBUG enabled. It dumps an error: wrapper is disabled in the server configuration. That lead me to this: "Trust me, you do not want to include from URLs.".
Then I realized you're defining that constant with plugin_dir_url(), when what you need is a path. The following magic constant does the job:
include_once __DIR__ . '/competition_table.php';
Thanks to the feedback from #b__ I have managed to solve this issue.
For some reason, Magic Constants don't always work with wordpress, however, you can use it's equivalent to get the same effect:
include_once dirname(__FILE__) . '/competition_table.php';
When including files for use in a wordpress plugin you should always include via a PATH, not by a URL.

Including another MySQL class in Wordpress

I have a Wordpress installation, say in localhost/blog/ path.
I also have another custom CMS installed in the root folder like localhost/ .
I want to include my CMS' MySQL class into the blog's installation, so in the blog theme's header.php, i include like so:
<?php
global $site_config, $_db // $_db is my CMS' equivalent to $wpdb;
include_once("../includes/class.query.php");
?>
I am able to access my CMS' database in the Wordpress blog.
However, some variables in the Wordpress like the author of the article went missing. Calling functions like "get_the_author_meta('ID')", "the_post_thumbnail('thumbnail')" returns empty string. Also gallery posted in posts gone missing too. Other content like the post content are working fine.
The content of the 'class.query.php' above is rather simple. I have narrowed it down to these few lines:
function connect()
{
if ($this->mysql_link = #mysql_connect($this->dbhost, $this->dbuser, $this->dbpass))
{
if (!mysql_select_db($this->dbase)) // <---- this is the line that screwed up the integration
{
....
I wonder if someone knows what's going on here. Why only some Wordpress functions are affected?
How can i fix this?
Thanks in advance.

Categories