I'm a PHP noob and have a question which seems to be simply - not as said, I'm a noob and can't solve it myself.
I have a wordpress blog running a template, and when searching without any searchresults, a error shows in the top of the page:
Warning: Missing argument 1 for get_page_id(), called in /var/www/titanen.dk/public_html/spillersmart/wp-content/themes/WPTube4/functions.php on line 262 and defined in /var/www/titanen.dk/public_html/spillersmart/wp-content/themes/WPTube4/functions.php on line 237
The functions.php can be seen here http://spillersmart.dk/functions.txt and a example of the page can be seen here http://spillersmart.dk/?s=xxx
Thanks in advance, guys! :-))
This problem sounds like it is somewhere within the theme, what the error means is: At line 262 inside functions.php this is happening.
function tube_getcustomfield($filedname, $page_current_id = NULL)
{
if($page_current_id==NULL)
$page_current_id = get_page_id(); //!HERE IS THE PROBLEM!
$value = get_post_meta($page_current_id, $filedname, true);
return $value;
}
The function get_page_id(); is being called without supplying an argument, and if you look at the definition for the function:
function get_page_id($page_name){
global $wpdb;
$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_status = 'publish' AND post_type = 'page'");
return $page_name;
}
This function requires one argument. Without getting a better look at how the theme has been built I don't know exactly how the get_page_id() function is being used. I wonder whether that line of code should be changed to
$page_current_id = get_page_id($filedname);
If this doesn't work then see if you can get a more up to date version of the theme you are using.
Related
I followed the syntax the best I could to create a shortcode on execution, I got the wsod. Once removed, all was well. But I don't know what is wrong with my code. This code sits inside 'My Custom Functions', a plugin for wp.
In researching how to write a custom shortcode, I discovered instructions here: https://torquemag.io/2017/06/custom-shortcode/ My expertise is in mysql and use mostly plugins in our wordpress website. I am very limited with coding.
function last_updated_shortcode {
$last_updated = $wpdb->get_results( "SELECT MAX(process_time) FROM
qgotv.last_updated");
return $last_updated;
}
add_shortcode( 'last_updated', 'last_updated_shortcode' );
This shortcode should retrieve a max(datetime value) from a db table so it can be displayed on a page. The query works. The qgotv db is separate from the wordpress db but can be accessed through wp.
Two issues I can see, one is that you have a syntax error in your function. When defining a function in PHP, you need to include the arguments parenthesis: function my_function(){ /* Do Stuff */ }. Also, you probably need to reference the $wpdb with the global keyword.
You can read up a bit on the $wpdb class as well as creating your own functions.
This should get you sorted out:
add_shortcode( 'last_updated', 'last_updated_shortcode' );
function last_updated_shortcode(){
global $wpdb;
$last_updated = $wpdb->get_results( "SELECT MAX(process_time) FROM qgotv.last_updated");
return $last_updated;
}
I have an old SS2.4 site which I have updated to SS3.1.13. The only part of the old site I can't get working is a search form that filters DataObjects. The old code is:
public function doCollectionSearch($data, $form)
{
$filters = array();
...
//setup some filters based on user selections
...
$where = implode(" AND ", $filters);
if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
$limit = $_REQUEST['start'].",50";
return $this->customise(array(
'Collections' => DataObject::get("Collection", $where, "Genus, Species ASC", null, $limit)
))->renderWith(array('Collection_results','Page'));
}
I have updated the last part to:
return $this->customise(array(
'Collections' => Collection::get()->where($where)->sort("Genus, Species ASC")->limit($limit)
))->renderWith(array('Collection_results','Page'));
But I get a "the method 'fortemplate' does not exist on 'CollectionPage_Controller'".
I know the $where is not right yet, but if I strip that out I still get an error..
I know I am missing something obvious...can anyone suggest a fix?
You'll get that error if your template accesses a method or database field that returns an object that can't be reduced to a string. This often happens when you have a related object (say a parent page) and you do something like the following:
<p>My parent is: $Parent</p>
Instead of
<p>My parent is: $Parent.Title</p>
The same thing existed in 2.4 so this doesn't totally explain your problem, but I'd look for something like the above scenario in your templates.
This code has been working good for months. The output consisted of a few lines containing statistics for a given username. The website from which the html page is taken is not down, and the content of the page in file_get_html hasn't changed.
All of a sudden (I checked and nobody modified it) it stopped working. Here's the relevant part:
[...]if ($FileAge > ($expiretime * 60) || 0 == filesize($cachename))
{
include_once('simple_html_dom.php');
$html = file_get_html('http://www.foo.com/search?what=user%3A'.YOUR_USER.'&search=Search');
var_dump($html); //TEST
$link = $html->find('.likeh4 lightGrey.', 0)->find('a', 0)->href; // Get the last activity link
[...]
The error log says:
[02-Feb-2013 17:02:19 Europe/Berlin] PHP Fatal error: Call to a member function find() on a non-object in /foo.php on line 22 (the line with $link).
var_dump($html) gives bool(false)
I have a similar script which parses an html page from another website. It stopped working as well.
[...]include_once('simple_html_dom.php');
$html = file_get_html('http://my.flightmemory.com/'.FLIGHTMEMORY_USER);
$chilometri_table = $html->find('table', 2); [...]
I tried to save on my webserver one of those html pages and I don't get such error.
Did my host disable some php function for security reasons? (actually, file_get_html comes from simple_html_dom and not from php native functions)
Any hints?
Thanks
It is probably way too late but:
Simple_html_dom has a constant to check given html size - MAX_FILE_SIZE. by default it's 600KB. It's enough for most cases, but if your given html is bigger than that, it will fail and returns false and causes that fatal error.
If you try to get [href]
I had same problem and fixed it.
need valid it's a simple_html_dom_node
if(is_a($html->find('.likeh4 lightGrey. a', 0),'simple_html_dom_node' )
$link = $html->find('.likeh4 lightGrey. a', 0)->href;
OR
foreach ( $$html->find('.likeh4 lightGrey. a') as $links ) {
$link =$links->href;
}
After reading the documentation, it seems that the correct way of doing that is like this:
<?php print $user_picture; ?>
Wich won´t work (it doesn´t print anything at all).
After asking around, I get this answer, which sadly won't work either:
<?php global $user;
$image = theme('user_picture', $user);
print $image;?>
That code was suggested as a "last resource", but when I try to use it, I get this error message:
Fatal error: Cannot use object of type stdClass as array in /includes/theme.inc on line 1054
Looking for that particular line: if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {, and in context:
if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
$element = $variables;
$variables = array();
if (isset($info['variables'])) {
foreach (array_keys($info['variables']) as $name) {
if (isset($element["#$name"])) {
$variables[$name] = $element["#$name"];
}
}
}
It's pretty clear that it should work, but it doesn't.
Using contemplate module, I get this output as an alternative:
<?php print $node->picture ?>
Which won't work either.
I've tried then with Devel module (using the /devel tab of the node):
I get this:
picture (String, 4 characters ) 2876
$...->picture
Which won't work, because the output is just "2876", but is the only "picture" there.
So what can I do? How can I trace this problem?
note that
theme('user_picture', $vars);
is a tpl.php file.
you can dpm($vars) of a preprocess function for this theme function and see what you can use.
As per node.tpl.php topic in Drupal docs, $user_picture is a valid variable in node.tpl.php file (and its variations like node--book.tpl.php)
This code is wrong:
<?php global $user;
$image = theme('user_picture', $user);
print $image;?>
it's about displaying picture of current user, and it's not for Drupal 7 AFAIK.
Try dsm($content) or dsm($node) in node.tpl.phptofind the correct variable if $user_picture is still not working for you.
I'm trying to "Import" the Wordpress core into an own script to use the functionality such as wp_query etc. I've created an script in a subdirectory (own framework) and want to extend it by wordpress, but everytime the script throws an error:
Fatal error: Call to a member function add_rewrite_tag() on a non-object in .../wordpress/wp-includes/taxonomy.php on line 333
such as (when I remove the add_action( 'init', 'create_initial_taxonomies', 0 )):
Fatal error: Call to a member function add_rewrite_tag() on a non-object in .../wordpress/wp-includes/post.php on line 1006
The non-object is the $wp_rewrite-object. I've echo'ed something and figured out that first $wp_rewrite is valid and at the next call not. I've changed nothing at the WP core files.
I try to include the core by calling:
require_once(BASE_PATH . 'wp-load.php');
Has anybody some ideas for me?
thanks
Short answer, do this:
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');
Long answer, it's a subtle gotcha around importing scripts with PHP.
If you define a local variable, outside of all functions, then it can be retrieved inside a function using 'global'. If you have a local variable inside a function, it cannot be retrieved later using global, unless it is defined as being global there and then.
The script 'wp-settings.php' is where the issue lies. It is included via your call to include 'wp-load.php'.
The variables defined there are not stated as being global; instead this is presumed because the script is always run outside of any functions, and so are automatically global. i.e.
$wordpress = 'foo';
function wordpressFunction() {
global $wordpress;
}
Because you are importing the script within a function, they now become local variables. You are essentially doing:
function myFramework() {
$wordpress = 'foo';
function wordpressFunction() {
global $wordpress;
}
}
So the fix is to define them as global yourself before importing the script. Now $wp_query, and the others defined as global, are correctly found.
The easiest way to access everything wordpress has programmed in is to use the following:
require_once('/../../../wp-blog-header.php'); // Use actual root path to wp-blog-header.php
header("HTTP/1.0 200 OK");
Using the above code you'll get all functions you would normally get using a template with in WordPress. I've tried all the other methods listed above and this one is by far the best.
I had the same error. I wanted to get some articles along with permalinks. This helped:
global $wpdb, $wp_rewrite;
require '/(...)/wp-config.php';
$result = $wpdb->get_results( $wpdb->prepare( ... ) );
foreach( $result as &$item )
$item->link = get_permalink( $item->ID );
I also found this useful in another case:
http://www.stormyfrog.com/using-wpdb-outside-wordpress/