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

gafa on "The limitation or error of $wpdb"

$
0
0

Hi for one page, I try to use a $wpdb->get_results() with a complex query (3 joints on the standard tables). The query runs directly on mySql, returns 2 results as expected, but $wpdb returns nothing !
My php code :

$wpdb->flush();
$request = 'SELECT posts.ID AS ID, posts.post_title AS post_title, posts.post_content AS post_content
FROM '.$wpdb->posts.' posts
LEFT JOIN '.$wpdb->term_relationships.' relationships ON relationships.object_id = posts.ID
LEFT JOIN '.$wpdb->term_taxonomy.' taxonomy ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id
LEFT JOIN '.$wpdb->terms.' terms ON terms.term_id = taxonomy.term_id
WHERE terms.name = "'.$pageTerm.'"
AND posts.post_type = "reference"
AND posts.post_status = "publish"
ORDER BY posts.post_date DESC
LIMIT 0, 2;';
$references = $wpdb->get_results($request);
The request generated is :
SELECT posts.ID AS myID, posts.post_title AS myPost_title, posts.post_content AS myPost_content FROM wp1_posts posts LEFT JOIN wp1_term_relationships relationships ON relationships.object_id = posts.ID LEFT JOIN wp1_term_taxonomy taxonomy ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id LEFT JOIN wp1_terms terms ON terms.term_id = taxonomy.term_id WHERE terms.name = "Restaurant" AND posts.post_type = "reference" AND posts.post_status = "publish" ORDER BY posts.post_date DESC LIMIT 0, 2;

This request returns 2 result in phpMyAdmin as execpted.

The return of get_results() is empty !!!

I already use $wpdb->get_results on other pages but with the request with only one joint.
Is it the problem ?

If anybody have an idea, feel free to help.


hans@jonkhof.nl on "Redirecting old pages to new pages on a wp site"

$
0
0

I migrated a Pixelpost photo site to wordpress, I also changed it to another subdomain. What I would like is to have an index.php in the old subdomain which leads users following existing links to photo's to the same photo on the new wp site. Fortunately the photo numbers did not change.

The old pixelpost url was:
http://foto.jonkhof.nl/index.php?showimage=589

The new url is:
http://fototest.jonkhof.nl/?p=589

Is it hard to script such an index.php, or can I find such a script somewhere? All help is appreciated!

scorch20 on "Adding search bar via Shortcode to .php template"

$
0
0

http://westonfit.com/programming-and-classes/large-group-training/trx-classes/

I need to add this piece of code to display ajax search bar.

echo do_shortcode('[wpdreams_ajaxsearchpro id=4]');

as you can see, I have added to the site, however I would like to align above the drop down menu or in the page title bar. Not sure where or how to add to align correctly. Any suggestions or answers are greatly appreciated.

The code as is. (up to end of header)

<?php
//FrankPoint 2013 © all rights reserved
//Validated HTML5 with semantic structure
get_header();
$path = get_template_directory_uri();

//Page variables
global $post;

//Get page ancestors
$ancest = get_post_ancestors($post->ID);

//Get page depth
$depth = wt_get_depth($post->ID);

//print_r($ancest);

//Page Parent Title
if ( is_page() && $ancest[1] ) {

$parent_title = get_the_title($ancest[1]);

} else {
$parent_title = get_the_title($ancest[0]);

}
?>

<!--[ 100 ]--><body>
<!--[ 200 ]--><header id="headBAR">

<?php // [fp] > Add MASTHEAD chunk.
get_template_part( '/chunks/masthead', '' );
?>

<!--[ /200 ]--></header>
<!--[ 300 ]--><section class="page">

<header id="pageHEAD" class="clearfix">
<div id="pageLABEL"><?php echo $parent_title; ?>AZCD<?php echo do_shortcode('[wpdreams_ajaxsearchpro id=4]'); ?></div>

<?php // [fp] > Add DROPDOWN chunk.
get_template_part( '/chunks/navdrop', '' );
?>

</header>

more ...

djhackraj on "Deeplink"

$
0
0

How To Create DeepLinking Tool...

Jast Like Auto Affilate Links ....

robertosalemi on "data entry from outside"

$
0
0

Hello to all,
I need to create an application that will allow me to send via post insertion smartphone.

A member of staff is developing the app that lets the user login and sending the content of the post (title, specular imaging + text).

I'm writing the pages in PHP (using the functions of WP):
1) a page that checks the login details
2) a page that receives the data and inserts it into the database.

What do you think?
It 'a correct way to follow or not?

Thank you.

Myar on "rewrite rule for ?tag=&category_name="

$
0
0

Hi!

I need the rewrite rule for htaccess, to get mydomain.de/apple/fruits from mydomain.de/?tag=apple&category_name=fruits

I want to build some tagsites as topic pages and style them indivudally and have a summary of excerpts of some categories and build a menu to the categories with post with the explicit tag.

For this existing rules:

ModPagespeed off
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

I hope you understand waht I mean, I'm not so good in english ;)

lieutenantdan on "wpdb update"

$
0
0

Everytime I try and use the wpdb update it never works but doesn't throw any errors...

$wpdb->update("wpjb_job",
				  array('confidential' => $value),
				  array('id' => $this->getObject()->getId())					  );

this is the 'error' i get.. Image

and yes, those are the correct table names and everything.

I've even been able to use the same sql statement in phpmyadmin and it will execute perfectly.

Ricardo on "Force rewrite rules when updating in Multisite"

$
0
0

In many of my WP sites, custom post type and taxonomy URLs return 404 errors right after certain updates. Fixing this is as easy as flushing rewrite rules visiting the Permalinks page, but when you're updating multiple sites at once this can be very annoying.

So I thought a possible solution could be to force a flush right after any plugin, theme or core update. And I came pretty close:

function flush_after_update() {
	global $wp_rewrite;
	//If multisite, we loop through all sites
	if (is_multisite()) {
		global $wpdb;
		//Pick up all active sites
		$sites = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain FROM wp_blogs WHERE archived = '0' AND spam = '0' AND deleted = '0' ORDER BY blog_id", '' ) );
		//Loop through them
		foreach ($sites as $site) {
			//Switch to current site
			switch_to_blog($site->blog_id);
			//Rebuild rewrite rules for this site
			$wp_rewrite->init();
			//Flush them
			$wp_rewrite->flush_rules();
			echo 'Rewrite rules flushed for site ' . $site->blog_id . ' (' . $site->domain . ').<br />';
		}
		//Back to normal
		restore_current_blog();
		$wp_rewrite->init();
	} else {
		//Flush rewrite rules
		$wp_rewrite->flush_rules();
		echo 'Rewrite rules flushed.';
	}
}
//Hook it up
add_filter('upgrader_post_install', 'flush_after_update', 10, 2);

The single-site part works just fine. The problem is in Multisite, and I think it is because $wp_rewrite->init() doesn't bring the rules for custom post types and taxonomies.

What do you think? Can this code be fixed? Does anyone have a better approach?

Thanks in advance,

Ricardo


Sinsabit on "Does changing link to an upload change the upload's properties"

$
0
0

File properties question, hope Hacks is best forum for it!

Say I create two MS word (or pdf) files "draft" and "final" on say 12th June and then upload them to the "uploads" directory on wordpress.

I link to the "draft" fill in a post and after about a month think oops! I should have linked to the "final" file.

If I were to change the link to the final file would you expect the "created" and "modified" properties to change from 12th June?

mrfraz on "Last 7-Days-News"

$
0
0

I have a Snippet for Posts for today by categorie.

Can i Change this to the last 7 Days? (seperate by day not category)

<?php
$today = getdate();
$categories = get_categories(array('hide_empty' => 1, 'orderby' => 'id', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None')));
foreach ($categories as $category) {
    query_posts('year='.$today["year"].'&monthnum='.$today["mon"].'&day='.$today["mday"].'&post_type=post&post_status=publish&cat='.$category->term_id);
    echo "  <li>\n"
        ."    <span class=\"tag-headline\" href=\"".get_category_link($category->term_id)."\">".$category->name."</span>\n<p class=\"tag-headline-border\"></p>"
        ."    <ul>\n";
    while (have_posts()) : the_post();
?>

posts

<?php
    endwhile;
    echo "    </ul>\n"
        ."  </li>\n";
}
?>

shihabmalayil on "what error in my CPT and Template ?"

$
0
0

Hi this is CPT with custom fields.



<?php
add_action('init', 'wlg_cstm_register');  

 function wlg_cstm_register() {  

	$product_labels = array(
    'name' => _x('Products', 'post type general name'),
    'singular_name' => _x('product', 'post type singular name'),
    'add_new' => _x('Add New', 'product'),
    'add_new_item' => __('Add New Products'),
    'edit_item' => __('Edit Products'),
    'new_item' => __('New product'),
    'view_item' => __('View Products'),
    'search_items' => __('Search Products'),
    'not_found' =>  __('No Products found'),
    'not_found_in_trash' => __('No Products found in Trash'),
    'parent_item_colon' => ''
);

	$product_args = array(
         'labels' => $product_labels,
         'public' => true,
         'show_ui' => true,
         'capability_type' => 'post',
         'hierarchical' => false,
         'rewrite' => true,
         'supports' => array('title', 'editor', 'thumbnail'),
		'taxonomies' => array( '' ),
        'menu_icon' => get_bloginfo('template_directory') . '/images/products-icon.png',  // Icon Path
        'has_archive' => true
        );

     register_post_type( 'product' , $product_args );
	 register_taxonomy( 'brands', 'product', array( 'hierarchical' => true, 'label' => __('Product Brands'), 'query_var' => 'brands' ) );
 }

 add_action("admin_init", "admin_init");
add_action('save_post', 'save_points', 1, 2);
function admin_init(){
  add_meta_box("productInfo-meta", "Product Details", "product_meta_options", 'product', "normal", "high");
}

function product_meta_options(){
  global $post;
  $custom = get_post_custom($post->ID);
  $category = (!empty($custom["_category"][0])) ? $custom["_category"][0] : '';
  $brand = (!empty($custom["_brand"][0])) ? $custom["_brand"][0]  : '';
  $id = (!empty($custom["_productid"][0])) ? $custom["_productid"][0] : '';
  $features = (!empty($custom["_features"][0])) ? $custom["_features"][0]  : '';
  $holds = (!empty($custom["_holds"][0])) ? $custom["_holds"][0]  : '';
?>
<table>
    <tr>
        <td>Category</td>
        <td> <input type="text" size="100" name="category" value="<?php echo $category; ?>" /> </td>
    </tr>
    <tr>
        <td>Brand</td>
        <td> <input type="text" size="100" name="brand" value="<?php echo $brand; ?>" /> </td>
    </tr>
	<tr>
        <td>Product ID</td>
        <td> <input type="text" size="100" name="productid" value="<?php echo $productid; ?>" /> </td>
    </tr>
    <tr>
        <td>Features</td>
        <td><?php wp_editor( $features, 'features', $settings = array('textarea_rows'=>20) ); ?></td>
    </tr>
    <tr>
        <td>Holds</td>
        <td><?php wp_editor( $holds, 'holds', $settings = array('textarea_rows'=>20) ); ?></td>
    </tr>
</table>

<?php
}

function save_points($postid,$post){
  global $_POST;
  // set the ID to the parent post, not the revision
  $postid = (wp_is_post_revision( $postid )) ? wp_is_post_revision( $post ) : $postid;
  $post_type = get_post_type( $postid );
  if ('product' == $post_type) {
    update_post_meta($postid, "_category", $_POST["category"]);
    update_post_meta($postid, "_brand", $_POST["brand"]);
	update_post_meta($postid, "_productid", $_POST["productid"]);
    update_post_meta($postid, "_features", $_POST["features"]);
    update_post_meta($postid, "_holds", $_POST["holds"]); // save the data
  }
}

function todo_restrict_manage_posts() {
    global $typenow;
    $args=array( 'public' => true, '_builtin' => false );
    $post_types = get_post_types($args);
    if ( in_array($typenow, $post_types) ) {
    $filters = get_object_taxonomies($typenow);
        foreach ($filters as $tax_slug) {
            $tax_obj = get_taxonomy($tax_slug);
            wp_dropdown_categories(array(
                'show_option_all' => __('Show All '.$tax_obj->label ),
                'taxonomy' => $tax_slug,
                'name' => $tax_obj->name,
                'orderby' => 'term_order',
                'selected' => $_GET[$tax_obj->query_var],
                'hierarchical' => $tax_obj->hierarchical,
                'show_count' => false,
                'hide_empty' => true
            ));
        }
    }
}
function todo_convert_restrict($query) {
    global $pagenow;
    global $typenow;
    if ($pagenow=='edit.php') {
        $filters = get_object_taxonomies($typenow);
        foreach ($filters as $tax_slug) {
            $var = &$query->query_vars[$tax_slug];
            if ( isset($var) ) {
                $term = get_term_by('id',$var,$tax_slug);
                $var = $term->slug;
            }
        }
    }
    return $query;
}
add_action( 'restrict_manage_posts', 'todo_restrict_manage_posts' );
add_filter('parse_query','todo_convert_restrict');

add_filter( 'manage_edit-product_columns', 'my_columns' );
function my_columns( $columns ) {
    $columns['brands'] = 'Brands';
    $columns['category'] = 'Category';
    unset( $columns['comments'] );
    return $columns;
}
add_action( 'manage_posts_custom_column', 'populate_columns' );
function populate_columns( $column ) {
    if ( 'brands' == $column ) {
        $brand = esc_html( get_post_meta( get_the_ID(), 'brand', true ) );
        echo $brand;
    }
    elseif ( 'category' == $column ) {
        $category = get_post_meta( get_the_ID(), 'category', true );
        echo $category;
    }
}

page template code



<?php
$wp_querty = new WP_Query( array(
	'post_type'    => 'product', 'post_status'  => 'publish') ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<?php the_post_thumbnail(); ?>
<?php echo esc_html( get_post_meta( get_the_ID(), 'category', true ) ); ?>
<?php echo esc_html( get_post_meta( get_the_ID(), 'brand', true ) ); ?>
<?php echo esc_html( get_post_meta( get_the_ID(), 'productid', true ) ); ?>
<?php the_content();?>
<?php echo apply_filters('the_content', get_post_meta($post->ID, 'features', true)); ?>
<?php echo get_post_meta( $post->ID, 'holds', true ); ?>

<?php endwhile; else: ?>
<?php endif; ?>

here productid field not saving data others saving correctly. and all custom fields not showing content in the page. the editor and title only showing content.
please help me to clear this issue.

mathieuhays on "manage wp user query output"

$
0
0

Hi everyone,

I don't manage to use the wp_user_query output through jQuery.

Array[1]
0: Object
>ID: 3
>allcaps: Object
>cap_key: "*****wp_capabilities"
>caps: Object
>data: Object
>>ID: "3"
>>display_name: "Machin"
>>user_activation_key: ""
>>user_email: "***"
>>user_login: "machin"
>>user_nicename: "machin"
>>user_pass: "****"
>>user_registered: "2013-07-04 12:20:26"
>>user_status: "0"
>>user_url: ""

Why jQuery ?
I'm getting this through an Ajax process (JSON) and i want to get all the 'ID', 'user_login', 'display_name' informations on jQuery.

Thanks.

PS: I spend my day looking for a solution without knowing which keywords would lead me to the right answer. Sorry if I double the entrie.

miguel@gabard.se on "Uninvited guests"

$
0
0

Hi!
How can I filter uninvited guests who leevs mesages in other lenguages (for example chinese)? They register them selvs as subscribers and I have to work x-tra time to delete them every day.
Miguel

JPry on "WP_Query in admin bar breaks post editor"

$
0
0

Hello,

I've written a plugin that, among other things, adds a custom menu to the Admin Bar. This menu uses a custom WP_Query object to retrieve a list of a specific custom post type, and then builds a menu from that list.

I'm finding that when the WP_Query object returns posts, it breaks the post editor. Here's what it does:

  • Shows "Auto Draft" for the post title
  • Shows the permalink as "http://example.com/?post_type=CPT&p=####", where "CPT" is the slug of the custom post type, and "####" is an ID number.

The above occurs when attempting to add a new post, and also when attempting to edit an existing post. Note that I am trying to edit a normal post, and not the custom post type in question.

Here's the code that I'm using to add the custom menu: https://gist.github.com/JCPry/5127193

Here's a screenshot of the menu that is created: http://screencast.com/t/B10xRgSeWsbU

Here's a screenshot of what I see when I click on "All Posts" or the edit link for an existing post (note: don't be fooled by the word "Story" in the screen capture. I have simply filtered the post labels): http://screencast.com/t/B10xRgSeWsbU

Here's a screenshot of what I see if I disable the menu item, or if the WP_Query in the menu does not return any posts of the custom post type: http://screencast.com/t/NzNh5SVlM

My main question is this: Is this issue due to something that I'm doing incorrectly in my code? Or is this possibly a bug in WordPress? I have spent some time digging through the WordPress code for the /wp-admin/post-new.php page, and I can't see how a call to WP_Query is causing this odd behavior.

I've tried to provide all of the information that I can, but of course if anything is not clear, please don't hesitate to ask for clarification.

negyvas on "query post random order but with even exposure?"

$
0
0

Hello,
I am new to this community and wordpress, but I am already loving it :)
I have found a lot of cool information here, but not for my current problem. I am building custom banner slider for exposing 5 banners. I can pull random pictures and show banners in slider in random order, but I need them to be exposed in even number of exposures. So all my advertisers will be exposed the same number of times. Is it hard to do?


Howdy_McGee on "Guide to Restrict Role From Pages"

$
0
0

I'm looking for a guide or something to follow to play around with restricting role access from a page and all it's sub pages. I've looked around on the googles and I've looked through the codex but I'm having trouble with it. Does anyone have links to good role restriction tutorials?

Vahan4033 on "Add new column in "posts" table?"

$
0
0

Hi I want to add new custom column to post table and display wordpress loop sorted by that column. Is it possible or not.... will wordpress work normally or I have to do additional changes in core?

Now I do that but values of that column with post ids are kept in separate table (I wrote custom query to db) but I have performance issues it runs 10 times slow than wordpress loop does.

I want to have very fast execution because blog has growing content and it will have about 100 000 articles in near time. I don't want to use post meta table.

Any advises?

Thanks!

djtari on "How to remove page=optionsframework option"

MatthewRuddy on "Image Resizing Function - An Alternative to Timthumb"

$
0
0

Hey all. I've been working hard on updating my plugin the 'Easing Slider'. A fairly massive update is on the way, and being a slideshow plugin image resizing is always a hot topic.

I had been using Timthumb (like a lot of people), but often spent quite a while looking for a WordPress based alternative. I came across the 'vt_resize' function, which initially I felt did the trick, until I found out it wouldn't upscale images (which was vitally needed). It wasn't a good enough solution.

So I bit the bullet and decided to come up with my own function. It is heavily based on some of WordPress's internal resizing functions, except it crops identically to Timthumb itself.

It also supports the upcoming WordPress 3.5 update (an alternative function is used via an 'if' statement), which gives us access to some handy image manipulation classes to ease the pain.

So far after a bit of testing it appears to be working very well. I'm really happy with it. It saves the resized images in the WordPress uploads folder, as per usual. This is great, because not only are the images resized but they are static files, which is ideal.

I've created a Github page for the function here. It is released under GNU general public license, so feel free to use it as you wish!

http://matthewruddy.github.com/Wordpress-Timthumb-alternative/index.html

There is only one drawback: it won't work with external images. It's just too complicated and slow to do so, and probably not worth the effort. If you need to resize an external image, save it to your computer and upload it to the WordPress Media Library. Then use it from there.

That's it really. If anyone finds any bugs, then let me know and I'll get them sorted quickly!

Now you've no excuse to use Timthumb at all!

uniquelylost on "is_page theme options not working"

$
0
0

Hi, I created theme options to insert a page title into a function but can't seem to get it to work... if I manually enter the page title into the is_page it works though. Here's my code-

function emr_single_page_only(){
		if (is_page($emr_options['pagetitle_url'])) {

Thanks in advance for any suggestions :)

Viewing all 8245 articles
Browse latest View live




Latest Images