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

Manan on "WordPress Custom Post Type Query"

$
0
0

I have this query for custom filed values (array based values):

<?php
    // args
    $args = array(
        'numberposts' => -1,
        'post_type' => 'villa',
        'meta_query' => array(
        'relation' => 'AND',
            array(
                    'key' => 'amenities',
                    'value' => 'Internet',
                    'compare' => 'LIKE'
                )
            )
        );
    // get results
    $the_query = new WP_Query( $args );

    // The Loop
?>
<?php if( $the_query->have_posts() ): ?>
    <ul>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
        <li>
            <?php echo the_title(); ?>
        </li>
    <?php endwhile; ?>
    </ul>
<?php endif; ?>

Now I want to generate bellow part dynamically:

array(
            'key' => 'amenities',
            'value' => 'Internet',
            'compare' => 'LIKE'
        )
    )

Bellow is my implemented code but now working:

$amenities_exp = explode(",", $villa_amenities);
    $aCount = 0;

    $args = 'array(
          \'numberposts\' => -1,
          \'post_type\' => \'villa\',
          \'meta_query\' => array(
          \'relation\' => \'OR\',';

    for($a=0; $a<count($amenities_exp); $a++){
        "array(
                'key' => 'amenities',
                'value' => '".$amenities_exp[$a]."',
                'compare' => 'LIKE'
            )";
        if($aCount != count($amenities_exp) - 1){
            echo ",";
        }else{
            echo "";
        }
        $aCount++;
    }

    "));";

pixelkai on "Remove thumbnail dimensions from wp_caption"

$
0
0

i am using the following code in functions.php to get rid of the inline thumbnail dimensions generated by wordpress :)

// Remove inline width and height added to images
function remove_thumbnail_dimensions( $html ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; }
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
// Removes attached image sizes as well
add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );

this works fine excepted for images which are added through wp_captions shortcode :(

so i thought i just add another filter
add_filter( 'img_caption_shortcode', 'remove_thumbnail_dimensions', 10 );

but for some reason it willl not work :(

adragt on "Nav Menu Item Linking to Today's Posts"

$
0
0

Would it be hard to have a link in the menu that always gathered the posts/events for the current date? So you could have a link that just said "Todays' Events" and it would just link to whatever events(posts) are happening on whatever date it happens to be?? Thought I'd throw it out here and see if anyone knows

I *think* it has something to do with get_day_link but I really can't figure out how to make a menu item out of that.

Thanks!

clickmac on "Adding Drag and Drop for user uploads"

$
0
0

if their is any such plugin, i don't think it would be for free

frengo70 on "sticky post"

$
0
0

Hello.
I have a little problem that the theme designer can't resolve.
http://www.motoinlombardia.it/test2
In the middle of page there is a boxed named "areaonoff" that show the latest 5 news of the category.
I need to enabled stick post in this loop.
but with my mods i can show only the sticki post and not sticky+post
how i can do please?
francesco

<?php
$sticky = get_option( 'sticky_posts' );

query_posts('cat='.$cat->cat_ID.'&showposts=5&p=' . $sticky[0]);
while(have_posts()) : the_post();
?>

jellesn on "Contact Form 7 - jQuery checkbox"

$
0
0
$(document).ready(function() {

        //Hide the field initially
        $("#hide3").hide(); 

        //Show the text field only when the third option is chosen - this doesn't
        $('#nieuwsbrief').change(function() {
                if ($("#nieuwsbrief").val() == "Ja") {
                        $("#hide3").show();
                }
                else {
                        $("#hide3").hide();
                }
        });

});
[checkbox* nieuwsbrief id:nieuwsbrief "Ja"]

<div class="hide" id="hide3">
[email email]
</div>

How to get this working? With select it works perfectly..

Riccardo on "Force download not working as expected"

$
0
0

On PHP I usually I use these lines of code to force a download:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream', true, 200);
header('Content-Disposition: attachment; filename="MY_FILENAME"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
ob_clean();
ob_flush();
flush();
readfile('MY_FILE_PATH');
exit();

Now I tried to include the WordPress enviroment to it simply adding this on top of it:

require_once(dirname(__FILE__) . '/wp-load.php');

But now instead of instantly opening the browser download file dialog, the script runs for minutes (this lasts more for bigger files, it looks like the server is downloading the file) then only after this the browser shows the download file dialog where the user could clicks OK and starts the real download.

If I comment out the WordPress include it works as expected.

I have to use it for remote files, but it looks the same also on local files.

I tried various combinations of output buffering cleaning, flushing and restarting too.

Any hint on what feature of WordPress could cause this?

Hidoshi on "Echoing PHP inside of PHP with a link"

$
0
0

My familiarity with PHP is a little rusty right now. I'm trying this:

<?php
if ( has_post_thumbnail() ) {
	echo ("<div class="content-left" style="background-image:url( '" . $image_url[0] . "' );"></div>");
}
else {
	echo 'Blah';
}
?>

Which, according to my hack-together understanding, should get me an if/else situation where the background image gets pulled from the post thumbnail, or it just prints "blah" if none is available.

Now, the code for the post thumbnail is fine. It works properly. Introducing the if/else PHP, however, has broken it. I feel like I'm just missing a key piece of syntax in here. Anyone have any ideas? Thanks!


hovida on "WP_Query - Meta with Arrays"

$
0
0

Hey guys,

i try to work a little bit with meta_query on the pre_get_posts action and i have a little Problem.

I have a custom Post-Type "news". On the edit-page i had added a custom meta box. Here the user can select the visibility of the news. For example:
Metabox Screenshot

Options (postmeta and usermeta) will be stored as Array (serialized) in the metadata, like:
PMA - Postmeta
PMA - Usermeta

But how i can combine the meta-querys with Arrays?

add_action('pre_get_posts',						array($this, 'pre_get_posts'));

function pre_get_posts($query) {
			if($query->query_vars['post_type'] == 'news') {
				$user				= wp_get_current_user();
				$user_company		= get_user_meta($user->ID, '_user_company', true);
				$user_company		= empty($user_company) ? array() : (array) $user_company;
				$user_company[]		= 'all';
				$user_company[]		= 'front';

				$query->set('meta_query', (array(array(
					'key'		=> '_news_visibility',
					'value'		=> $user_company,
					'type'		=> 'array'
				))));
			}

			return $query;
		}

Data - The _news_visibility is an array. For example:
array( 'all', 1 )

_user_company from the userdata is an array like:
array( 1, 2 )

Fi Fi P on "JQuery Trouble"

$
0
0

I have been looking through a lot of documentation for this and really need a good clear tutorial if one exists. I have made the move from Dreamweaver to Wordpress and would like to implement some javascript actions.
From a previous topic I have followed I have created a folder 'js' in my child them area and in this I have a tutorial.js file with my JQuery code.
The code below has then been inserted within my home-page.php file just before the div I want to add an action to:

<!--CALL CUSTOM JS -->

<script type="text/javascript" src="../wp-includes/js/jquery/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../js/tutorial.js"></script>

I have then added a 'j' after each use of $ within my JQuery file.

It doesn't work. Any ideas on how I can do this?! There is a lot of threads about this but none are very clear as to what is to go where!
Any help would be really appreciated! xx

Piotr on "Dynamically adding forms and options"

$
0
0

I'm continuing my work on a Wordpress site that uses forum posts as content (more on this can be found here and here).

After creating news section which takes first post of every topic and turns it into a Wordpress post I need something more complicated - a section of articles. This requires taking the first post of a topic and appending the remaining posts to the first one - just like chapters in the article. And actually this is something that I've already achieved. I'm using a second query to get posts from a topic, and by using variables for topic IDs and post IDs I can even specify which posts will be imported and appended. The problem is I need to be able to add, edit or remove topics and posts IDs from the query. After using settings API in the news section I thought that it wouldn't be too difficult to use it here, but sadly it is. And this is where I need help.

What I need is an options page that will list all the topics and posts IDs, and let me add, edit or delete these settings and will update the list. I tried to use the settings API, to add a pair of forms every time an option is added, but I'm not even close to what I need. I'm not even sure if storing a multidimentional array ( article# => array( topic_id => 'value', posts_ids => 'values' ) ) as an option is a good idea. I'll be grateful for any ideas.

Ale12 on "adding 'author_id' as part of register_taxonomy parameter- How to"

$
0
0

Hello,

Hope you all well.

I would like to have a list of taxonomies by author. I searched google and WordPress forum and There are couple answers which were closed. However, it does not fit blog's requirement

The blog that we run is a multi-authors blog with different user role.

Here are some questions.

Can I add "author=>$current_user->id" to taxonomy.php file and get a list of taxonomy by author using function WP_Tax_Query($author_id)?

Please see the block of code below

If there is no option to get taxonomy by author available and I have to add author to taxonomy.php above, What other files that code need to be changed for example, template/core files and database table? Could you please let me know the files' name.

What would be a recommended practice so that when new Wordpress release, it would be easy to maintain and update?

global $current_user; // will add code
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
	global $wp_taxonomies, $wp;

	if ( ! is_array( $wp_taxonomies ) )
		$wp_taxonomies = array();

	$defaults = array(
		'labels'                => array(),
		'description'           => '',
		'public'                => true,
		'hierarchical'          => false,
		'show_ui'               => null,
		'show_in_menu'          => null,
		'show_in_nav_menus'     => null,
		'show_tagcloud'         => null,
		'meta_box_cb'           => null,
		'capabilities'          => array(),
		'rewrite'               => true,
		'query_var'             => $taxonomy,
		'update_count_callback' => '',
		'_builtin'              => false,
                'author'                => $current_user->id, /not sure if I need a comma here ***will add code here **/
	);
	$args = wp_parse_args( $args, $defaults );

I think it might be helpful if we can list a category/taxonomies by authors but I might be wrong.

Thanks very much for your help.

Have a nice, warm and sunny day.
-A

josh5723 on "Load New Header File On Certain Pages"

$
0
0

I've searched a bunch on this issue and have found many people giving different advice. I will only need 2 different header files for my site, the original and the new one I've since created (titled header-second.php).

I'll want header-2 to appear on multiple pages, identified by their Page ID. How do I accomplish this the easiest? An if tag in the index.php file?

This is included on the multiple headers page:

<?php
if ( is_home() ) :
	get_header( 'home' );
elseif ( is_404() ) :
	get_header( '404' );
else :
	get_header();
endif;
?>

How do I alter this for specific page IDs? I've tried adding this to index.php, but it changed nothing and still loaded the original header.php.

<?php
if ( is_page(417) ) :
	get_header( 'second' );
else :
	get_header();
endif;
?>

Do I need to add this code to all .php files where get_header is present? What am I doing wrong?

Thanks a lot!

adeizasama on "Reassigning post thumbnail issue"

$
0
0

Hi,

I'm working on a site and I'm trying to make it search through the images in the post to come up with a post thumbnail.

The thing is, when you add the image to the post while creating it, it picks the thumbnail straight away, but when you add an image after the post has been published, it doesn't change the already assigned default image.

Here is the code for the thumbnails:

// Get image attachment (sizes: thumbnail, medium, full)
function get_thumbnail($postid=0, $size='full') {
	if ($postid<1)
	$postid = get_the_ID();
	$thumb_key = get_theme_mod('thumb_key');
	if($thumb_key)
		$thumb_key = $thumb_key;
	else
		$thumb_key = 'thumb';
	$thumb = get_post_meta($postid, $thumb_key, TRUE); // Declare the custom field for the image
	if ($thumb != null or $thumb != '') {
		return $thumb;
	} elseif ($images = get_children(array(
		'post_parent' => $postid,
		'post_type' => 'attachment',
		'numberposts' => '1',
		'post_mime_type' => 'image', ))) {
		foreach($images as $image) {
			$thumbnail=wp_get_attachment_image_src($image->ID, $size);
			return $thumbnail[0];
		}
	} else {
		return get_bloginfo ( 'stylesheet_directory' ).'/images/login-logo2.jpg';
	}

}

And here is the website -> web.ugometrics.com.

Most of the posts with the issue have the "ugometrics" logo as the thumbnail, for your consideration.

Any ideas?

Thanks

robthirlby on "format of user_email field"

$
0
0

Is there a legal hack to change the validation of user_email fields to allow say rob<rob@thirlby.net> or rob(rob@thirlby.net)? I'm unclear why the validation via is_email() is so restrictive effectively to name@domain.


kmadrid on "Media query question"

$
0
0

Wondering if there is any way I can use a media query to construct a new window or tab url if the user is accessing via mobile, versus a modal pop-up if the user is accessing via monitor. I've tried eight gazillion different modal window plugins and css/js/html to get the content to work on a phone; unfortunately the content for the modal window was provided by a government agency with strict instructions not to reformat, and it just doesn't work in a mobile modal popup. Also, the url content is updated with numbers via javascript, so that needs to work too. Advice?

merlin867 on "Add a waiting time for admin"

$
0
0

Hello everyone,
First, I would like to apologize for my english. I'm french so it's not so easy for me.

For my problem I did a little research. but frankly I'm not sure what I'm looking for exactly ! :/

I have a part of my plugin that find info on another website and made ​​the parsing to retrieve specific information. So far, all is well. In fact, the script works fine. The only point where I do not know what or how to do is on the wait. Because for each record in the database , there is a waiting time of about a 1-2 sec. This waiting time will not be "lived" by the user, but only by the admin who decide when to trigger the update procedure .
Here is the code that is triggered by the administrator :

global $wpdb;
    $price_query = 'SELECT * FROM wp_prix';
    $price_list = $wpdb->get_results( $price_query );
    foreach ( $price_list as $price ) {
        $monprix = afficher_prix($price->url);
        $monid = $price->prix_id;
        echo $wpdb->update( 'wp_prix', array('prix' => $monprix ), array( 'prix_id' => $monid));
    }

The waiting time is at "afficher_prix($url)" function.

Is there a way to perform the processing in background or put a " rolling circle " or a progress bar in the meantime? For the moment, at the stage of creating the plugin I have a dozen recording. So the wait time is minimal , but when I turn it on I expect nearly a thousand recording ... This will dramatically increase the waiting time .

I am very open to suggestions !
thank you
Francois

rapportdesign on "New User Notification Email Include Name"

$
0
0

I've modified the New User Notification Email to include address details entered during the shopping cart of WooCommerce, but I also need to include the first and last name.

The following code will print the last name matching the hard coded ID...

$user_last = get_user_meta( 5952, 'last_name', true );
$message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

Why does the following not print the last name matching the new users ID?

$user_last = get_user_meta( $user_id, 'last_name', true );
$message .= sprintf(__('Last Name: %s'), $user_last) . "\r\n\r\n";

The following prints the correct ID that I'm trying to target, so this makes little sense to me...

$message .= sprintf(__('User ID: %s'), $user_id) . "\r\n\r\n";

If anyone has any suggestions, I'd be very grateful.

onyudo on "What's the best way to directly link to a post's file attachment?"

$
0
0

I have a portfolio where there are a series of thumbnails. Clicking on a thumbnail leads to the portfolio post's permalink (i.e., the_permalink(); ). Attached to each portfolio post is a PDF file.

What is the most direct way to link the thumbnail directly to the PDF file attached to the portfolio post?

armaniworld on "autofill form from another on my site"

$
0
0

I have two forms my site, one on the homepage and one on the "search results page"

i am using a plugin to create the homepage form (wp custom fields search)

and the search results form is done by custom code,

what i need is,

for example a user enters "london" in location field on homepage, then hits search,
and then on the search results page the location field will automatically have "london" inputted,

is this possible?

thanks

Viewing all 8245 articles
Browse latest View live




Latest Images