Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

Juanfra Aldasoro on "[Runtime Error?] Fatal error: Call to undefined function is_user_logged_in()"

$
0
0

Hi there,

I'm writing a plugin in which I relate some posts and data.

I'm having the following problem:

- I have a function ie: prefix_get_post_by_meta(), and it contains something like:

function prefix_get_post_by_meta( $meta_value ){

	$args = array(
					'numberposts'	=> 1,
					'post_type'	=> 'my_post_type',
					'meta_key'		=> 'my_key',
					'meta_value'	=> $meta_value
				);

	// get results
	$the_query = new WP_Query( $args );

	// The Loop
	if ( $the_query->have_posts() ) :
		while ( $the_query->have_posts() ):
			$the_query->the_post();
			return get_the_ID();
		endwhile;
	endif;

	wp_reset_postdata();

	return false;
}

Everything goes great with that function.

The problem is that at certain point when I use this function in another function for a shortcode or in the front end it doesn't return anything.

Imagine I have another function my_shortcode_function()

function my_shortcode_function(){

       $my_id = prefix_get_id_from_api(); // this gives a unique ID that match with the custom field value
       $the_post_id = prefix_get_post_by_meta( $my_id );
       $output = '';

       if ( $match_id ){

           $output .= '<h1>' . get_the_title( $the_post_id ) . '</h1>';
	   $output .= '<h1><a href="'. get_permalink( $the_post_id ) .'">' . get_the_title( $the_post_id ). '</a></h1>';

      }else{
           $output .= 'Nothing for the ID ' . $my_id;
      }

      return $output;

}

add_shortcode( 'my_shortcode_function', 'my_shortcode_function' );

----
If I invoque the function directly from the shortcode, I get nothing as a response, when the post actually exists.

If I modify the function to echo the $output, and add that as an action for the init:

add_action( 'init', 'my_shortcode_function' );

I get the accurate result on the backend. On the front end, I get the wrong result.

----

If I stay with the echo instead of returning the $output, and I call the function directly on my plugin, like

my_shortcode();

Then I get this:

Fatal error: Call to undefined function is_user_logged_in() in /Applications/MAMP/..../wp-includes/query.php on line 2778

It's obvious that is a runtime thing. Is there something that I'm missing?

Every query function end up using WP_Query(), that's why I assumed that this wasn't the problem, am I right? (I tried with get_posts just in case and the same happened).

any help is super appreciated :)

Juanfra.


mrpolab on "Multiple loops and pagination"

$
0
0

Hi everybody,
are you ready for my strange help request?
ok, let's start.
I need to paginate my multiple loops shown on the home: the first loop contains 2 posts from one category (some sort of featured), the second loop 8 post from all the categories, but obv i don't whant the same article is shown twice in both loops.
I need the first loop to disappear from the non-first pages, so both in the home and only the second loop from the second page to the end.
This are the loops now:

<?php
// Let's fix pagination issue first

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

if(1 == $paged) {
}

$args=array(
	'post_type' => 'post',
	'post_status' => 'publish',
	'paged' => $paged,
	'post___in' => 'cat=32',
	'posts_per_page' => 2
);
$wp_query = new WP_Query('cat=32');
$wp_query->query($args);
?>
<?php if ( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
	//First loop template here

	<?php endwhile; ?>

<?php
// Let's fix pagination issue first

if ( get_query_var('paged') ) {
	$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
	$paged = get_query_var('page');
} else {
	$paged = 1;
}

$args=array(
	'post_type' => 'post',
	'post_status' => 'publish',
	'paged' => $paged,
	'post__not_in' => $do_not_duplicate,
	'posts_per_page' => 8
);
$wp_query = new WP_Query();
$wp_query->query($args);
?>
<?php if ( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
// Secon loop template here
<?php endwhile; ?>
	<?php wp_reset_postdata(); ?>
<?php endif; ?>

	<?php if(function_exists('wp_pagenavi')): wp_pagenavi(); ?>
	<?php else: ?>
		<?php global $wp_query; if($wp_query->max_num_pages > 1) { ?>
		<div class="navigation clearfix">
			<span class="prev"><?php previous_posts_link( __('&larr; Previous', 'warrior') ); ?></span>
			<span class="next"><?php next_posts_link( __('Next &rarr;', 'warrior') ); ?></span>
		</div>
		<?php } ?>
	<?php endif; ?>
		<?php wp_reset_postdata(); ?>

<?php endif; ?>

s.clause on "php in category description"

$
0
0

Does someone have solution for adding PHP code into category description? I am trying to find something on internet over 4 hours, but without success. I really need to put PHP code into category description. I have multiple categories and for each one of them i need a different PHP code into description. Is there some way how to do it?

I really need help with this, i don't know what else to do.

EdHynan on "TinyMCE plugin (3.x & 4.x): switch Visual->Text and back, contents marked dirty"

$
0
0

Working on a tinymce plugin to make a pretty rendering for a shortcode used by my WP plugin. Code is based on the wpeditimage tinymce plugin from WP core. Have equivalent code for tinymce 3.x and 4.x, and both show the same bug.

The bug: load an editor page. The "Visual" tab is selected and tinymce is shown, and my plugin has worked as expected so far. Select "Text" to get the plain textarea, my plugin still works because the original shortcode is shown. Select "Visual" again, and again all seems to be good. With no edits, navigating away from the page (e.g. selecting a left side menu item) gets the 'Are You Sure?' prompt, indicating that the content is considered changed!

The wpeditimage plugin does not show this bug, and I've spent ridiculous time studying that for something I missed -- plus the tinymce code, of course. No joy.

Any clues?

I have a nearly minimal test plugin that shows the bug; I'll put it up for DL if anyone wants to look.

SpidermanPuddin on "Select Query for Taxonomy Meta Data"

$
0
0

I'm trying to query by custom meta data from a taxonomy. I haven't been able to get a Select Query to work so I have a work around:

$queried_object = get_queried_object();
	$series_id = $queried_object->term_id;  

	$volume_array = array();

	$volume_list = get_terms("volume", array( 'hide_empty' => 0 ) );
	if( $volume_list ){
		foreach( $volume_list as $volume ){
			$t_id = $volume->term_id;
			$term_meta = get_option( "taxonomy_$t_id" );
			if( $series_id == $term_meta['series_value'] ){
				$volume_array[] = $t_id;
			}
		}
	}

I know there has to be a better way to do this.

joker1234 on "WPDB Update only the first row"

$
0
0

I have this code, and I want to update only the first row found where the times column is equal to 0, but it updates all.

$dbHost = 'host';
$dbUser = 'user';
$dbPass = 'pass';
$dbName = 'name';

$mydb = new wpdb($dbUser,$dbPass,$dbName,$dbHost);

$table_name = 'users';

$data = array(
	'username' => 'name'
);

$where = array( 'times' => 0 );

$format = array( '%s' );

$where_format = array( '%d' );

$mydb->update( $table_name, $data, $where, $format, $where_format );

How can I achieve this? Thanks.

Da9L on "Should i use Transient API or Cookies?"

$
0
0

So im making a plugin, that relied on SESSION data.. Which i just now figured out is not working in Wordpress..

So as an alternative i would have used cookies, but came accross the Transient API in Wordpress..

Now i cannot decide which to use..

What are the pros and cons on each of them ?

dharmendrakumar on "Add new administrator user It more then 1000 so please help me."


Power Design on "Incorporating Google Books API with using ISBN and Custom Fields"

$
0
0

Hello,
My client wants to display some recommended books on their site. So far, I have my theme set up so that when my client enters the ISBN of the book into the Custom Field "ISBN" for a post, it will retrieve the cover image from Google Books. That worked for awhile, but now I believe I have reached my anonymous limit for using Google Books API, and need to incorporate the OAuth into the process. Is there a way to get my Client ID for Google Books API in the header.php? Or am I approaching this problem completely the wrong way?

I have no knowledge of making Plugins, but I can edit php files for Themes. This is how I am currently getting the book covers:

<div class="book-cover"><?php
$isbn = get_post_meta($post->ID, 'ISBN', true);
$page = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn:$isbn");
$data = json_decode($page, true);
$cover = $data['items'][0]['volumeInfo']['imageLinks']['thumbnail'];
echo "<img src='$cover' />";
?>
</div>

Any help with this is greatly appreciated!

jinseiichido on "Please help me converting this login in python to php(wp)"

$
0
0

Hello.

I have come up with this idea in python but being unfamiliar with php is not helping so I would like some help converting this python logic to php that can work with wordpress.

I want to get tags info assigned to a main article in single.php.
Then I have a dictionary(python) setup so a tagId is assigned an image.
so tag1 is assigned to image1.jpg
tag2 is assigned to image2.jpg and so on.
I want to display 4 different images on web, that are assigned to associated tags.
If the article has more than 4 tags assigned then I want to get 4 random tags so i can only display 4 images. If there are less than 4 tags assigned to the article then I just want to display them all.

here is the logic in python, hope someone can help. thank you.

# python
# in single.php
# get tags of this article
tags = getTagsOfThisArticle()
# assign images to tagIds
assignments = {"tagId1":"/img/path/1.jpg","tagId2":"/img/path/2.jpg","tagId3":"/img/path/3.jpg"}
# get 4 random tags - not the cleverest method but you get the idea
tagsRandom = []
import random
if (len(tags) > 4): # if there are more than 4 tags assigned
    random.sample(tags, 4) # get 4 random tags
else:
    tagsRandom = tags
# at this point, i should have 4 random tags(or less) this article is assigned to
for (tag in tagsRandom):
    # display the images
    print '<img src="'+assignments[tag]+'">

Tesssupport on "Fatal error: Cannot redeclare get_url_999() Can't access site at all"

$
0
0

I don't know the version of WPress I am using because I cannot access my site. I did an upgrade through my FTP, so perhaps it is the latest?

Here's the whole message:
Fatal error: Cannot redeclare get_url_999() (previously declared in /home/content/29/9329929/html/wp-content/themes/pagelines/functions.php(2) : runtime-created function(1) : eval()'d code(1) : eval()'d code:1) in /home/content/29/9329929/html/wp-content/themes/pagelines/functions.php(2) : runtime-created function(1) : eval()'d code(1) : eval()'d code on line 1

I need help knowing which folder to change/edit, etc. Thanks so much in advance!!

3Lancer on "Wordpress user typed searches"

$
0
0

Hi,

What's the best way to go about limiting the Wordpress search character length.

For example:
Preventing user's from searching only one character, does this help with server load?

Preventing user's from spamming the search button?

Prevent user's from typing in very long search words, this seems to currently end up in with a blank page?

weirdrat on "how to eliminate google-fonts totally"

$
0
0

hi, can anyone please help a non-scripter like me to get totally rid of google-cloud-fonts in the wordpress-hardcode ? Not only deactivate them - I found several scripts for this - but what do I have to cancel from the wordpress basic code to eliminate any google-connection like if it never had existed .. and other question: are there still enough "normal" self hosted fonts inside ? I saw that even the dashboard now uses this google-crap and want my normal fonts like arial, helvetica, verdana etc back and dont want to leave a trace of this spy-crap google - and please I do not need any advices how useful google fonts are etc - I just want to get rid of them .. thanks a lot in advance .. the rat

nikki007 on "wp_cron usage"

$
0
0

I customized a spider calendar plugin which shows today's birthdays and current months list of wedding anniversaries in the home page of the site. i wrote a code in that plguin's displaying page using wp_mail and mail will send. but this happens only when the site is visited. my code:

if($dat==date('Y-m-d'))/*$dat is the date of event from DB*/
 {
  if($eid!=''){ /*if recipient email id is not null*/
 if($se!=1)  /*if email is sending first time then($se=db column 'send'value) $se=0    otherwise it is 1*/
  {
    $to=$eid;
    $sub="Birthday Wishes";
    $msg='Happy Birthday '.$ev_title[$j];
    $headers= 'From:Mysite <noreply@mysite.com>' . "\r\n".'Content-type: text/html';
    $attachments=array(WP_CONTENT_DIR . '/plugins/spider-event-calendar/images/happybday.gif');
    $rx=wp_mail($to,$sub,$msg,$headers,$attachments);
    $wpdb->update($wpdb->prefix.  "spidercalendar_event",array('send'=>1),array('id'=>$ev_id[$j]));/**/
    //echo "email send";
    }
  else{
  //echo "email already sent";
      }
    }
  }

i heard aboywp_cron. as i'm a newbie can anyone please tell me how should i write a cron from the above function to perform.and how to start the cron.

websupporter on "admin_enqueue_scripts hook & internationalization"

$
0
0

Hi everyone,
I am currently struggeling with a small problem. Well, I've coded a workaround, but I am not very happy about it and I would appreciate your thoughts on this.

I am programming a plugin, which supports internationalization. This plugin adds also menus on the Adminpage. For the dashboard I run the following functions:

  • add_menu_page()
  • The action hook "admin_enqueue_scripts"

So, this is what happens:
add_menu_page( __( 'Menu Title', 'textdomain' ), __( 'Menu Title', 'textdomain' ), 'edit_posts', 'slug', 'admin_output_index', SF_URL . 'icon.png', 81 );

I add a menupage with the translateable Title 'Menu Title'. And I add some submenupages.

In order to load my styles and Javascripts only on my menupage und subpages I use the action hook "admin_enqueue_scripts":

add_action( 'admin_enqueue_scripts', 'adminscripts' );
function adminscripts( $hook ){
	if( !in_array( $hook, array( 'toplevel_page_menu-title' ) ) )
		return;
	/* Register Scripts and Styles */
}

The $hook tells me, wether I am on one of my adminpages or not. My hooks are placed in an array. If the hook is not found in this array, my scripts and styles won't load.

I've expected this hook to be stable, but it isn't when it comes to internationalization, because part of the hook derives from the second "add_menu_page"-Parameter:
_( 'Menu Title', 'textdomain' )

So, in the moment, I run this script on another language, the hook changes and my scripts doesn't load. For now, my "workaround" is simply not to translate the second parameter, but this is a rather poor solution.

I am not quite sure, wether I shall call this a "bug" in WordPress or if I do not quite understand the whole "hook"-idea. But, before I now start to open a ticket or report to the core developers, I think its better to discuss this here.

I am quite interested, what you guys think :)

All the best


keendev on "Media Gallery Attachment Details Category Taxonomy"

$
0
0

Hi All,

I've got an interesting question I'd like to pose to you all, this might be a better fit for the advanced forum. However here goes:

Below is an image:

Media Gallery Example

I currently have Wp Media Gallery plugin installed.

Wp Media Gallery

Now inside this plugin the author registers the category taxonomy to the attachment post type, now thats all nice and dandy. This will make a category taxonomy text field show up in the attachment details section (highlighted in red in image above). Now what I'd like to know is:

1. Where is the code in the wordpress core which decides to add a field there?
2. Is it possible to add other fields their that will get saved as well. (Most likely a taxonomy)

Kind Regards

teampaif4life on "Black Ninja Mailer error"

$
0
0

Getting error 360
object already loaded

and I loaded all the OCX files and stated

teampaif4life on "Black Ninja Mailer 2.0 error"

$
0
0

getting error 360
object already loaded

and I loaded all the OCX files as stated

gsexton on "PHP Version Strangeness - Different versions in same host"

$
0
0

I have a plugin that needs PHP 5.3 or higher. A customer has reported a problem. In my code I have:

if ( !defined( "PHP_MAJOR_VERSION" ) || // PHP_MAJOR_VERSION came in 5.2.7
( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 )) {
// We need at least 5.3 to get the DateTime class.
$cdaily_version_check=false;
} else {
$cdaily_version_check=true;
}

later in the code I have:

if ( !$cdaily_version_check ) {
echo '<div class="error cdaily-error"><p>'.__('Your system is using PHP version '.phpversion( ).'. The minimum supported PHP version for this plugin is 5.3.0, released June 2009. Please ask your system administrator to upgrade your PHP version to at least 5.3.','cdaily_plugin').'</p></div>';
}

When I go to my configuration page it displays the version as 5.2.17. I shoved phpinfo() into my page and it reports 5.2.17 with server API being "CGI".

However when I go to a page that he has, it shows version 5.3.28 with server API being "CGI/FastCGI"

It really appears that the "wp-admin" path is running in a different version of PHP than other parts of the virtual host or even other paths like /wp-content/. Has anyone ever seen anything like this?

The hosting company is web-hosting. Has anyone ever seen this where parts of a host run in one version of PHP and other parts run in a different version?

Maynard on "Looking for some advice on a filter-gallery functionality"

$
0
0

Hello!

I've been working with wordpress building sites for clients for a couple of years, and I have a lot of experience with tweaking layouts and their css for the most part. I can code html and css comfortably enough, though I usually use Adobe Muse for non-CMS related projects, and I'm somewhat familiar with php and jquery. I've gotten through a few projects heavily modifying the php of a couple of different layouts, so my confidence in my ability to get the end result is pretty strong.

Now that you know about me, what I'm trying to do is a rather unique image gallery setup. The layout is a fixed sidebar on the left and a responsive gallery to the right. This gallery would be several dozens/hundreds of thumbnails all at a fixed height but varying widths, and all images would be aligned to the left and covered with a 50% black overlay. This would be like an infinite gallery so it loads quickly. There will be a list of several categories on the left hand sidebar, and when you hover over the category the overlay will be removed from those thumbnails in the gallery on the right hand side, giving it a 'highlight' effect. When the category is clicked, it will open a gallery page of just those images on a carousel type setting. This second carousel gallery is not a problem for me to make, but the hover-over-category-name-to-highlight-those-images seems difficult.

I've done a lot of research and found some portfolio gallery plugins I would be glad to purchase that do almost what I want, but none have the "trigger/category name" on the left hand side, always at the top. Most of these plugins require a fixed image width as well. I would like the rows of images to be responsive.

I'm thinking this may be able to be achieved by having a page of posts that are all floated left with no borders or spacing between, but the last piece of the puzzle is that highlight-hover feature. Could somebody please point me in the right direction for this? I know it may be a lot of work, but I've got to get it done and I'll learn anything I need to. I just want the most effective way of doing what I'm talking about. I know this can be done, I just need to have a good idea of how to execute it.

Thanks in advance, and I'm sorry if I'm being super vague. I can make a design mockup if you wish. I could even make the pages from scratch with all the functionality I need, I just need the content to be able to be changed without changing the whole site, so that's why I've come here. Please let me know!

Viewing all 8245 articles
Browse latest View live




Latest Images