WP―button to start media library - wordpress

I am creating a wordpress plugin and I would like to enable the user to use images from the media library. For example: the »Choose Image« button in the »header« section of Theme configuration does exactly what I am looking for.
Is there any wordpress method I can call to generate such a button?
Greetings philipp

what you try to accomplish is not clear,
using all the images is one thing and give them an option to use wordpress uploader is one thing.
give them the last option is not recommended because they can abuse your system without control.
to see all the images you can use this function, return an array :
function get_all_images(){
$args = array(
'post_type' => 'attachment',
'post_mime_type' =>'image',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
$images = array();
foreach ( $query->posts as $image) {
$images[]= wp_get_attachment_url($image->ID);
}
return $images;
}

Related

why "WP Search Suggest" plugin search only product data instead of all?

I am using this WordPress plugin which link is: https://wordpress.org/plugins/wp-search-suggest/
In this plugin there is a method called ajax_response and has a code like that:
$query_args = apply_filters( 'wpss_search_query_args', array(
's' => $s,
'post_status' => 'publish',
), $s );
$query = new WP_Query( $query_args );
now I use print_r($query) to check which post_type is calling. Now I see its only calling post_type = 'product' :(
I need to search page or post as well.
How can I do this?
Update: The form has the id attribute already:

wordpress one-page website with different php pages

I'm trying to build a wordpress website. I'd like to have a one-page design. I have built 5 pages
each one has its own php file. How can I do to concatenate the 5 pages in one single page?
Thank you in advance for your help,
Fabiana
You may not need to use multiple pages at all but implement inbuilt function for wordpress like shortcodes, or use posts and make multiple queries to the post. You can then design your page (1) in sections and make sure to make $loop = new WP_Query( $args ); to enable multiple queries on the same page. These queries would/should only query post not pages.
Section 1 Layout
$args1 = shortcode_atts (array(
'tag' => 'post-type',
'post_type'=> 'post',
'cat' => '', // Category ID
'posts_per_page' => 1,
'bgimageurl' => ''), $atts);
$query1 = new WP_Query( $args2 );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
the_content();
wp_reset_postdata();
Section 2 Layout
$args2 = shortcode_atts (array(
'tag' => 'userchoice',
'post_type'=> 'post',
'cat' => '', // Category ID
'posts_per_page' => 1,
'bgimageurl' => ''), $atts);
$query2 = new WP_Query( $args2 );
You can take a look at this plugin for wordpress which provides a way to create full screen scrolling pages by using fullPage.js plugin.

How to get Wordpress attachments to work for existing images inside the Media Library?

I want to display the images from each Wordpress post on a separate page.
When using get_children (or get_posts) the 'post_type' => 'attachment' only works if I've just uploaded an image (via WP's 'ADD MEDIA > UPLOAD FILES') to that particular post.
It does not work if I add an existing image to a post that's already in my WP MEDIA LIBRARY).
Is there anyway for 'attachment' to work for existing (already uploaded) images?
See my test function:
function echo_first_image($postID){
$args = array(
'post_type' => 'attachment',
'post_parent' => $postID
);
$attachments = get_children( $args );
if($attachments){
echo'YES'; // test answer
}else{
echo'NO'; // test answer
}
}
EDIT: each 'post_type' that is an 'attachment' has a single 'post_parent' - does this mean an attachment can ONLY have a single parent?
Currently as of writing, Wordpress 4.1 does not include multi-parent attachments because the database relationship is one-to-one, not one-to-many. You would have to find a plugin, or write your own to get around that.

how to add new pages using WP core function

how can I add a page using core functions of wordpress.I can find function for Post etc as well but couldn't find any for Pages.Any one who can help me
Thanks
You use the same function to add posts or pages, just add the post_type parameter like this :
$args = array( 'post_type' => 'page',
'post_content' => 'You content...',
'post_parent' => $parent_id; // ID of the page this one should be a child of
... // etc.
...
'post_title' => 'Title for your page');
wp_insert_post ($args);

How to fetch all WordPress posts with featured image?

In WordPress 3 there is Featured Image functionality. How do i fetch all posts that have a featured image with them? Here is my current custom loop:
$loop = new WP_Query( array( 'posts_per_page' => 15 ) );
This should work:
$loop = new WP_Query( array( 'posts_per_page' => -1, 'meta_key' => '_thumbnail_id' ) );
I haven't tested this, though. Also, this will probably fetch all posts and pages. Use 'post_type' => 'post' to limit it to blog posts.
I don't believe you need any special loops defined for that to work.
Though you do need to add some small snippets into your functions.php
like this one:
<?php add_theme_support ( 'post-thumbnails' ); ?>
after apply the above code to functions.php file, your theme will support Featured Images and you will see a new link # the bottom right of your Post Add / Edit interface.
This guide will help you, if you are looking for more info regarding this : How to Use Wordpress Featured Image Feature

Resources